Thread: Newbie IO questions

  1. #1
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    Posts
    244

    Newbie IO questions

    Hi!
    1) What is the difference between these two functions:
    Code:
       fscan( stdin , ¨%d¨, integer );
     
       scanf( ¨%d¨ , &integer );
    I know that fscanf is used to read files, but I see a lot of fscanf in books, just to read from the stdin. Isn't better use scanf, once that is smaller?

    2) How can I simulate an EOF from the console? Supposing that I want to make a program that can read from the console or a file?

    Thanks for all replys!!
    Nothing more to tell about me...
    Happy day =)

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    1) Provided the calls are correct:
    Code:
    fscanf(stdin, "%d", &integer);
    scanf("%d", &integer);
    There's no difference. fscanf is more generic than scanf as it can read from any input stream. scanf is restricted to stdin except when stdin is redirected.

    2) For the most part, DOS and Windows systems use the ctrl+z keyboard combination to flag EOF on the console, *nix systems typically use ctrl+d.
    My best code is written with the delete key.

  3. #3
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    This computer lets me use both CTRL+C and CTR+Z, I'm on win ME

  4. #4
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Originally posted by Draco
    This computer lets me use both CTRL+C and CTR+Z, I'm on win ME
    Ctrl-C doesn't send EOF. it sends TERM.

  5. #5
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    ah..I see........I was unaware. Well, now for the obvoius follow up...what is TERM?

  6. #6
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    Posts
    244
    Thaks you all!
    Nothing more to tell about me...
    Happy day =)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie questions
    By raptorx in forum C Programming
    Replies: 2
    Last Post: 10-10-2007, 09:30 PM
  2. more newbie questions - file io
    By sunzoner in forum C++ Programming
    Replies: 1
    Last Post: 06-13-2002, 04:33 AM
  3. Barrage Of Questions...Theory impossible? File IO on Web Domain?
    By MagiZedd in forum Windows Programming
    Replies: 0
    Last Post: 10-24-2001, 08:13 PM
  4. Episode II Return Of the newbie : Website IO Question
    By MagiZedd in forum Windows Programming
    Replies: 1
    Last Post: 10-18-2001, 08:58 PM
  5. Real newbie with VC6 questions
    By MagiZedd in forum Windows Programming
    Replies: 8
    Last Post: 10-15-2001, 08:27 PM