%i and %d place holders.

Player's Avatar, Join Date: Aug 2007
Go4Expert Member
Hi Guys.

Another quick question for you. I have just come across the %i place holder but i don't understand the difference between %i and %d. The section in my book that lists all the place holders says there both int place holders. In the program i am looking at it don't explain why the %i is used instead of %d. It's the first time i have come across the %i place holder. Sorry if it's a dumb question but i need to know everything
0
asadullah.ansari's Avatar, Join Date: Jan 2008
TechCake
% i attempts to take as integer.
%d attempts to take decimal integer.
0
asadullah.ansari's Avatar, Join Date: Jan 2008
TechCake
This example makes you more understand...

Code: c
#include <stdio.h>

int main()
{
   char InStr[] = "150 0125";
   int val1=0, val2=0;

   //******* Reading integer values*****///
    sscanf(InStr, "%i %i ", &val1, &val2);
   //****************************************

    printf("The Decimal values are : %d %d\n", val1,val2);
    val1=0;
    val2=0;

    //******* Reading Decimal integer values*****///
     sscanf(InStr, "%d %d", &val1, &val2);
   //****************************************

    printf("The Decimal values are : %d %d\n", val1,val2);
    return 0;
}

Output::

asadulla ~/temp> gcc test1.cc
execution gcc-3.3.1
asadulla ~/temp> ./a.out
The Decimal values are : 150 85
The Decimal values are : 150 125

Last edited by asadullah.ansari; 6Feb2009 at 10:29.. Reason: code block