Quzah's printf and scanf tutorial...

This is a discussion on Quzah's printf and scanf tutorial... within the C Programming forums, part of the General Programming Boards category; Since about half of the last ten posts have been failure to use printf and scanf correctly, I thought I'd ...

  1. #1
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Quzah's printf and scanf tutorial...

    Since about half of the last ten posts have been failure to use printf and scanf correctly, I thought I'd give you a tutorial:

    1) printf is used for output. All of the *printf functions work basicly the same way:

    printf( "format specifier", variables, variables, variables... );

    Example:

    int i = 10;
    float f = 11.11;
    char c = 'c';
    char *s = "string";

    To display this:

    printf( "I is %d, F is %f, C is %c, and S is %s\n", i, f, c, s );


    2) scanf works the exact opposite. All of the *scanf functions work basicly the same way:

    scanf( "format specifier", ptr2var, ptr2var, ptr2var... );

    int i = 0;
    float f = 0.0;
    char c = 0;
    char s[1024] = { 0 };

    scanf( "%d %f %c %s", &i, &f, &c, s );

    Notice that we require pointers, so on non-pointer variables, we must use the "address of" operator. Ie: the &.

    See, that wasn't so tough.

    Quzah.
    Hope is the first step on the road to disappointment.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >See, that wasn't so tough.
    So...use the address of operator for printf and don't use it for scanf? I got it, thanks quzah

    -Prelude
    My best code is written with the delete key.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Yes but how do I use clrscrn() in MSVC++?????



    j/k

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. Newb Help: Full Arrays and Functions
    By LycanGalen in forum C Programming
    Replies: 5
    Last Post: 01-31-2008, 08:35 PM
  4. Please help debug
    By Wexy in forum C Programming
    Replies: 2
    Last Post: 11-11-2002, 12:40 AM
  5. help with switch statements
    By Wexy in forum C Programming
    Replies: 3
    Last Post: 11-06-2002, 05:44 PM

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