here\'s the problem, thax 4 ur help :) Write a program that will compute the ave
ID: 3618857 • Letter: H
Question
here's the problem, thax 4 ur help :)Write a program that will compute the average word length (averagenumber of characters per word) for a file that contains some text.A word is defined to be any string of symbols that is preceded andfollowed by one of the following at each end: a blank, a comma, aperiod, the beginning of a line, or the end of a line. Your programshould define a function that is called with the input-file streamas an argument. This function should also work with the streamcin as the input stream, although the function will not becalled with cin as an argument in thisprogram. here's the problem, thax 4 ur help :)
Write a program that will compute the average word length (averagenumber of characters per word) for a file that contains some text.A word is defined to be any string of symbols that is preceded andfollowed by one of the following at each end: a blank, a comma, aperiod, the beginning of a line, or the end of a line. Your programshould define a function that is called with the input-file streamas an argument. This function should also work with the streamcin as the input stream, although the function will not becalled with cin as an argument in thisprogram.
Explanation / Answer
//Hope this will help you. #include #include #include #include using namespace std; void call_function(ifstream &myfile) { string line; char msg[1000]; char *ptr; int count_w=0,len_w=0; while (! myfile.eof() ) { getline (myfile,line); strcpy(msg,line.c_str()); ptr = strtok(msg," ,.; "); while(ptr !=NULL) { count_w++; len_w += strlen(ptr); ptr = strtok(NULL," ,.; "); } coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.