fscanf: read word from file

This is a discussion on fscanf: read word from file within the C Programming forums, part of the General Programming Boards category; Hi I have a file like that: 1 2 3 4 5 6 7 8 and I want print on ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    56

    fscanf: read word from file

    Hi

    I have a file like that:

    1 2 3 4 5 6 7 8

    and I want print on stdout:

    1 3 8

    in other words i want choose what print out.
    I was thinking to use fscanf as:
    Code:
    fscanf(file_in,"%d  %d  %d ", &a , &b, &c );
    but in this way i get:
    1 2 3
    Is there a solution using fscanf to obtain my purpose?

    Thanks
    D

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    56
    Hi

    I got it
    It's enough to insert a format type indicator, something like:

    fscanf(file_in,"%d %*1hd %d ",&a, &b,&c);

    D

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

Tags for this Thread


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