printf

This is a discussion on printf within the C Programming forums, part of the General Programming Boards category; Is my syntax ok? Code: printf("%i+%i=%i\n",array1[r],array1[h],array2[evencount]); I do not get anything printing. I want it to display similar to the ...

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Exclamation printf

    Is my syntax ok?
    Code:
    printf("%i+%i=%i\n",array1[r],array1[h],array2[evencount]);
    I do not get anything printing.
    I want it to display similar to the below
    1+1=2
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    what is the array. Unless the answer is already in the array it won't work. You might want something like this
    Code:
    printf("%i+%i=%i\n",array[1],array[2],array[1]+array[2]);
    I think this is standard?

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    why on earth are u putting %i and not %d you are using numbers im guessing ?

  4. #4
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Originally posted by liams7
    why on earth are u putting %i and not %d you are using numbers im guessing ?
    Maybe because he want's the functionality that %i has instead of %d -- so why not?
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    15
    because for what he is doing there seems to be no point and it looks so much more sexy LOL

  6. #6
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Originally posted by liams7
    because for what he is doing there seems to be no point and it looks so much more sexy LOL
    Oh, I don't know about that. I see %d everywhere. I find %i much more mysterious and sexy. I wish they;d introduce the %8 -- va va voom!!!
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  7. #7
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    Reason for the %i.
    I'm new to C, and my text book states you can use %i or %d for a place holder for integers, but does not state which is prefered.

    Why is %d perfered over %i?

    If you want to see the context of my syntax. Take a look at this post.
    errored program
    Last edited by xviddivxoggmp3; 03-16-2004 at 02:04 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  8. #8
    Registered User
    Join Date
    Feb 2004
    Posts
    72
    C: A Reference Manual
    The i operator is present in Standard C for compatibility with fscanf; it is recognized on output for uniformity, where it is identical to the d operator.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by WaltP
    Oh, I don't know about that. I see %d everywhere. I find %i much more mysterious and sexy. I wish they;d introduce the %8 -- va va voom!!!
    If you like them alone, wait until you get them together:
    Code:
    printf("%8i", number );


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

  10. #10
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    I believe the difference between %i and %d is %i accounts for hexadecimal values, whereas %d is strictly (d)ecimal. So you could go wrong .
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  11. #11
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >So you could go wrong .
    That's scanf. This thread is concerning printf.
    My best code is written with the delete key.

  12. #12
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Originally posted by Prelude
    That's scanf. This thread is concerning printf.
    ie, %i and %d are for all intents and purposes the same thing when used with printf.

    ~/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 09:38 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. segmentation fault upon reload
    By yabud in forum C Programming
    Replies: 8
    Last Post: 12-18-2006, 06:54 AM
  4. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 09:23 AM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 11:14 AM

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