Problems in opening a txt file in a loop

This is a discussion on Problems in opening a txt file in a loop within the C Programming forums, part of the General Programming Boards category; HI , I am trying to open a txt file in C and i am successfull in doing the same ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    14

    Problems in opening a txt file in a loop

    HI ,

    I am trying to open a txt file in C and i am successfull in doing the same , but the problem is that the contents of the file is displayed only the first time i execute the file
    the rest of the time
    a blank screen is getting displayed .

    the problem being once when the file is executed the variable ch reaches the value EOF

    how shd i point to the begining of file

    pls find below the code
    Code:
    clrscr();
    fp2=fopen("c:\\rules.txt","rb");
    while(1)
    if (ch==EOF)
    break;
     else
      {
      ch=fgetc(fp2);
      printf("%c",ch);
    }
    getch();
    fclose(fp2);
    pls help
    regards
    Anil

  2. #2
    Registered User
    Join Date
    Jan 2006
    Posts
    14
    HI all ,

    I managed to do that , i really wonder C is such a wonderful language , the more u think the more u get

    thnx all

    regards
    Anil

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem in opening a txt file
    By arian in forum C++ Programming
    Replies: 3
    Last Post: 06-07-2009, 01:17 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21