Thread: display problem

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    20

    display problem

    how can i chop the third line of the output...thanks

    data read from file as below:
    1231252 Peter(new line)
    1548587 Mary(new line)

    output as below:
    1231252 Peter
    1548587 Mary
    1248587 Mary

    Code:
    while (!feof(f))
    	{	int student_id;
    		char student_name[200];
    		fscanf(f,"%d", &student_id);
    		fscanf(f,"%s", student_name);
    		printf("id: %d\tname: %s\n",student_id,student_name);
    	}

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    As you're reading in the lines, count them. When your count is equal to three, don't print out the data from that line.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    As you're reading in the lines, count them. When your count is equal to three, don't print out the data from that line.
    That's a horrible way of doing it.

    mag_chan, you should read on Why it's bad to use feof() to control a loop. This explains why you are getting this unexpected behavior.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. new problem with class
    By jrb47 in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2006, 08:39 AM
  2. Display problem
    By Birdhaus in forum C++ Programming
    Replies: 1
    Last Post: 09-06-2006, 03:52 PM
  3. Replies: 2
    Last Post: 06-21-2006, 04:23 AM
  4. Display problem
    By RoD in forum C++ Programming
    Replies: 11
    Last Post: 10-09-2002, 05:25 PM
  5. display problem after retrieving from text
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 01-29-2002, 06:48 AM