Thread: consider this simple C query of mine...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    60

    consider this simple C query of mine...

    consider this simple code..

    #include <stdio.h>
    int main(void)
    {
    float sum = 3.3;
    printf("\n%s%12f\n\n sum:", sum);
    return 0
    }

    ---- (My queries move from left to right.. of the printf)

    1. the first \n causes the cursor to advance to the next line... yes?

    2. how about the first %s ? will it correspond to sum even if it (sum) has no double quotes ?

    3. how about %12f? to which will it correspond ?

    4. then the cursor advances 2 lines next.... right ?

    5. will it print the word sum: ?

    ---my apologies... but I have no idea (as yet..) of running C programs.. Thats why Im asking for advice... I soon will !!

    please advise me .... thanks !

  2. #2
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164

    Re: consider this simple C query of mine...

    Originally posted by imbecile in C
    consider this simple code..

    #include <stdio.h>
    int main(void)
    {
    float sum = 3.3;
    printf("\n%s%12f\n\n sum:", sum);
    return 0
    }
    >---- (My queries move from left to right.. of the printf)

    >1. the first \n causes the cursor to advance to the next line... yes?
    Yes

    >2. how about the first %s ? will it correspond to sum even if it (sum) has no double quotes ?
    Yes, and will print junk becase sum is a float

    >3. how about %12f? to which will it correspond ?
    Nothing. you need 2 elements for a 2nd %

    >4. then the cursor advances 2 lines next.... right ?
    Yes

    5. will it print the word sum: ?
    Yes.

    What I believe you want is:
    printf("\nsum=%12f\n\n", sum);
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    60

    Thanks !!

    Thanks dude ..!!

    I copied some exercises from the whiteboard...
    and all of us had the same thing...(errors in theory..)

    now I know our professor has something up his sleeve...

    I have taken full note of your comments !! (and perhaps the others next.. !!)

    this are my first steps.. and surely,.. I won't forget the tedious trail I've been through !!

    --Thanks !!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. query problem
    By arian in forum C# Programming
    Replies: 1
    Last Post: 08-18-2008, 01:49 PM
  2. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  3. Simple string query
    By ozzy34 in forum C++ Programming
    Replies: 3
    Last Post: 05-13-2004, 11:40 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Simple simple graphics
    By triplem in forum C Programming
    Replies: 2
    Last Post: 05-19-2003, 02:52 AM