Problem with my c assignment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • keoo
    New Member
    • Nov 2007
    • 5

    Problem with my c assignment

    Hi guys i need help... im trying to make this program, to count the number of paragraphs found in a particular text file. 10x
  • seforo
    New Member
    • Nov 2006
    • 60

    #2
    So .....? Where is the problem? What have you done?

    Comment

    • keoo
      New Member
      • Nov 2007
      • 5

      #3
      i have done dis part :-

      Code:
      #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;
        }
      and im finding problems to make it count the lines
      Last edited by RedSon; Nov 29 '07, 05:57 PM. Reason: CODE

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        You have no counter in your loop.

        Also, if you have to count paragraphs, how are you to identify a parargraph??

        Comment

        • oler1s
          Recognized Expert Contributor
          • Aug 2007
          • 671

          #5
          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

          Working...