I've been sitting here for 2 hours trying to figure out where to go with this code. I guess I just don't understand how strings work or how to use them at all...
Assignment
Write a program that reads in a text file and calculates the average number of non-space characters per line. Note: a. A text file, hw7dataf11.txt, is provided along with the assignment. b. The program can be divided into two parts: i. A function that receives a string and returns the count of the characters in the string. ii. The main function performs tasks like openning the file, adding the total characters and calculating the average.
My current code...
#include <iostream>
#include <fstream>
using namespace std;
int charcount(char characters[]){
}
int main()
{
ifstream inputFile;
inputFile.open("hw7dataf11.txt");
char characters[21];
int total = 0;
while (!inputFile.eof()){
inputFile >> characters;
total = total + charcount(characters);
}
return 0;
}
Seems like i just need to know how to count characters in a string now and fill in the function
Not asking anyone to finish it just need to know wtf to do now
Assignment
Write a program that reads in a text file and calculates the average number of non-space characters per line. Note: a. A text file, hw7dataf11.txt, is provided along with the assignment. b. The program can be divided into two parts: i. A function that receives a string and returns the count of the characters in the string. ii. The main function performs tasks like openning the file, adding the total characters and calculating the average.
My current code...
#include <iostream>
#include <fstream>
using namespace std;
int charcount(char characters[]){
}
int main()
{
ifstream inputFile;
inputFile.open("hw7dataf11.txt");
char characters[21];
int total = 0;
while (!inputFile.eof()){
inputFile >> characters;
total = total + charcount(characters);
}
return 0;
}
Seems like i just need to know how to count characters in a string now and fill in the function
Not asking anyone to finish it just need to know wtf to do now
Last edited: