Skip line in file - fscanf

This is a discussion on Skip line in file - fscanf within the C Programming forums, part of the General Programming Boards category; I'm making a program to read data from a table but the top row of the table will be headers, ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    8

    Skip line in file - fscanf

    I'm making a program to read data from a table but the top row of the table will be headers, which i dont want to be read. Is there any way to skip the top line in the file?

    Heres my code:
    Code:
    	if((fptr = fopen("table.txt", "r")) == NULL) //Open file.
    	{
    	    MessageBox(NULL, "Could not open the table file.", "noori_cw.exe", MB_OK); //error message.
    		return EXIT_FAILURE;
    	}
    
    
    	fscanf(fptr, "%d", &masknum); //Get number of mask textures to load.
    
    	for(i = 0; i < masknum; i++) //load mask info.
    		fscanf(fptr, "%s", &maskname[i]);
    Thanks for any help

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,673
    Just call fgets() to read the line.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    8
    Cheers, sorted it now

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. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM

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