Thread: Skip line in file - fscanf

  1. #1
    Registered User
    Join Date
    Apr 2007

    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:
    	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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.

  3. #3
    Registered User
    Join Date
    Apr 2007
    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
Website Security Test