Thread: if we have to output to stdout when should we use fprintf or printf

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    2

    if we have to output to stdout when should we use fprintf or printf

    if we have to output to stdout when should we use fprintf or printf

    fprintf(stdout,"asdfa",5);
    printf("asdfa");

    thanx in advance....
    awaiting a reply....

  2. #2
    Registered User
    Join Date
    Aug 2004
    Posts
    4
    Normally, If you would like to print to standard output you can go ahead with Printf, In case if you want to Print any thing to user defined Files, you can use fprintf.
    There is not much difference between printf and fprintf, if your writing to standard output

    Thanx,
    Gobinath

  3. #3
    ---
    Join Date
    May 2004
    Posts
    1,379
    Gobinath is right. Irrelevant to the question however, this is the prototype for fprintf()
    Code:
    int fprintf(FILE *stream, const char *format, ...);
    so im not sure why you put a 5 here
    Code:
    fprintf(stdout,"asdfa",5);

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    fprintf(stdout, "blah");

    is exactly the same as

    printf("blah");
    If you understand what you're doing, you're not learning anything.

  5. #5
    .
    Join Date
    Nov 2003
    Posts
    307
    Think of printf() as a "wrapper" for fprintf(stdout....)

  6. #6
    Registered User xxxrugby's Avatar
    Join Date
    Jan 2005
    Posts
    178
    Code:
    int  fprintf (FILE * stream , const char * format [ , argument , ...] );
    Print formatted data to a stream.
    Prints to the specified stream a sequence of arguments formatted as the format argument specifies.


    Parameters.
    stream
    Pointer to an open file.
    format
    String that contains the text to be printed.
    Optionally it can contain format tags that are substituted by the values specified in subsequent argument(s) and formatted as requested.
    The number of format tags must correspond with the number of additional arguments that follows.
    The format tags follow this prototype:

    %[flags][width][.precision][modifiers]type

    Code:
    int  printf ( const char * format [ , argument , ...] );
    Print formatted data to stdout.
    Prints to standard output (stdout) a sequence of arguments formatted as the format argument specifies.


    Parameters.

    format
    String that contains the text to be printed.
    Optionally it can contain format tags that are substituted by the values specified in subsequent argument(s) and formatted as requested.
    The number of format tags must correspond to the number of additional arguments that follows.
    The format tags follow this prototype:

    %[flags][width][.precision][modifiers]type
    Sorry for spelling errors, not English!
    xxxrugby: "All Human Race Will Die From My Hand!"
    xxxrugby: "We are all philosophers, when question is about politics!"

  7. #7
    former member Brain Cell's Avatar
    Join Date
    Feb 2004
    Posts
    472
    My Tutorials :
    - Bad programming practices in : C
    - C\C++ Tips
    (constrcutive criticism is very welcome)


    - Brain Cell

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems reading entered race times C
    By loopymoo26 in forum C Programming
    Replies: 12
    Last Post: 05-23-2009, 07:38 AM
  2. menu problem!!! need U R G E N T help!!!
    By catcat28 in forum C Programming
    Replies: 16
    Last Post: 11-19-2007, 01:32 PM
  3. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  4. Multithreading problem
    By Bacardi34 in forum C Programming
    Replies: 5
    Last Post: 09-02-2004, 02:26 PM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM