Thread: fscanf and whitespace

  1. #1
    Registered User
    Join Date
    Oct 2010

    fscanf and whitespace

    How do I use fscanf to capture whitespace? For instance, I have this written on the file:

    Seat 30A
    Arrow Smith
    I want to store Arrow Smith as a string variable, but how do I do this?

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    London, United Kingdom
    You use fgets and spare yourself the headache of using fscanf.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User
    Join Date
    Aug 2010
    fscanf with format specifier "%s"
    or better
    fgets + sscanf with format specifier "%s"

  4. #4
    Registered User
    Join Date
    Oct 2010
    How do you use fgets to capture formatted strings?

    For example, this seating information is among many others of the same type in the file. How do I store the strings for the first and last name while skipping over everything else?

    EDIT: Never mind, I got it. I didn't realize the buffer size has to match the actual array.
    Last edited by 843; 12-05-2010 at 12:20 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf %s or %d integer input space char stop question...
    By transgalactic2 in forum C Programming
    Replies: 5
    Last Post: 04-14-2009, 10:44 AM
  2. fscanf whitespace
    By BlkR in forum C Programming
    Replies: 10
    Last Post: 04-23-2007, 10:23 AM
  3. counting whitespace characters
    By artec_19 in forum C Programming
    Replies: 1
    Last Post: 10-30-2003, 01:50 PM
  4. white space and fscanf
    By DMaxJ in forum C Programming
    Replies: 2
    Last Post: 06-10-2003, 09:18 AM
  5. ignoring whitespace with fscanf
    By Viny in forum C Programming
    Replies: 1
    Last Post: 11-22-2001, 03:05 PM
Website Security Test