Hi guys i need help... im trying to make this program, to count the number of paragraphs found in a particular text file. 10x
Problem with my c assignment
Collapse
X
-
i have done dis part :-
and im finding problems to make it count the linesCode:#include <stdio.h> #include <stdlib.h> int main () { string line; ifstream myfile ("C:\\keo.txt"); if (myfile.is_open()) { while (! myfile.eof() ) { getline (myfile,line); cout << line << endl; } myfile.close(); } else cout << "Unable to open file"; getchar (); return 0; }Comment
-
You have no counter in your loop.
Also, if you have to count paragraphs, how are you to identify a parargraph??Comment
-
Have you even being going to class? You can't even get the code you posted correct. It's not minor mistakes either. Let's see: use of stdio.h and stdlib.h. For one thing, C headers are written as something like <cstdio> and <cstdlib> . You use something like string and getline (in <string>) and cout (<iostream>) and ifstream (<fstream>). Your use of eof is problematic, and you will see the last line in the file repeating twice.
I'm going to outright accuse you of not knowing the material, and trying to wing it. You haven't done a thing. Open a book, and start reading. We won't do your homework for you; see the posting guidelines.Comment
Comment