Thread: Keep reading lines in a file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    118

    Keep reading lines in a file

    I need to basically make a loop where i read everyline in a file but how would i tell the loop to stop when it reaches the end of a file?

    while (empinfo <<my filename != \0)

    i tired that but that was useless

    Code:
          empinfo = fopen("employees.dat", "r");
          if (fp == NULL) {
             printf("Cannot open &#37;s\n", fp);
             }
          else {
               /*printf("What is the 4 digit employee number: ");
               scanf("%s", first);*/
               do {
               fscanf(empinfo, "%d:%[^:]:%[^:]:%d:%lf\n", &empnum, last, first, &emprate, &emphours);
               printf("%s ", first);
               k++;
               } while (k != 6);
               fclose(empinfo);
               }
    thats what im doing right now, but i need it to find out when to stop since ill be adding lines into the file so i cant go into the code manually everytime
    Last edited by bigmac(rexdale); 12-01-2007 at 11:05 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Reading file into edit - losing new lines
    By eam in forum Windows Programming
    Replies: 3
    Last Post: 11-08-2003, 01:07 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM