Need help with fscanf question please

This is a discussion on Need help with fscanf question please within the C Programming forums, part of the General Programming Boards category; When reading data from a file that contains five integers per row (seperated by spaces) you want to keep only ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    6

    Need help with fscanf question please

    When reading data from a file that contains five integers per row (seperated by spaces) you want to keep only the first and last values in each row. Which of the following statements will correctly read the desired value into the variables x and y?


    A. fscanf(fptr, "%*d %***d %d", &x, &y);

    B. fscanf(fptr, "%d, %*d, %*d, %*d, %d", &x, &y);

    C. fscanf(fptr, "%d, %3d, %d, &x, &y);

    D. None of the above


    I thought that it would be the opposite of B and what you would want stored would be %*d, but answer B is the only one that would make sense to me...unless the answer was none of the above??/ (yuck)

    Thank you!!

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by quickclick330 View Post
    I thought that it would be the opposite of B and what you would want stored would be %*d
    You may think it, but it's not true A simple glance at the documentation for fscanf() will remove all doubt.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    6
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf in different functions for the same file
    By bchan90 in forum C Programming
    Replies: 5
    Last Post: 12-03-2008, 08:31 PM
  2. Quick question about fscanf
    By zyphirr in forum C Programming
    Replies: 16
    Last Post: 11-24-2008, 08:44 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM
  4. quick fscanf question...
    By Ham in forum C++ Programming
    Replies: 4
    Last Post: 02-01-2003, 07:47 AM
  5. fscanf() question
    By Encrypted in forum C Programming
    Replies: 6
    Last Post: 01-20-2003, 12:14 PM

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