the %c code is for print a char format
%d is for int
%s is for string
%f is for flotant's
2007-01-30 18:48:13
·
answer #1
·
answered by Anonymous
·
0⤊
0⤋
You should look in your compiler's help files or Google search printf to find out the parameters for the printf() function and how they are used.
%d prints the value of a variable in decimal with the ASCII number characters
%c prints the ASCII character of the value in a byte variable
Your printf() line is supposed to print 2 different values (%d and %c), so you have to specify 'a' twice after the %c"
If you wish to simplify, you can use 2 printf() statements like this:
printf("Decimal of a=%d\r\n",a);
printf("ASCII character of a=%c\r\n",a);
The '\r\n' moves the cursor to the left side of the screen and moves down one line.
There's something you should know about your program:
Since you want to print a byte, you should specify that the variable 'a' is an unsigned char, not an int. You need an unsigned char, because unsigned chars have a value of 0-255, whereas a signed char has a value of -128 to 127 and your loop runs from 1-254.
Try experimenting with this program:
#include
unsigned char a;
int main(void)
{
for (a=1;a!=255;a++)
printf("Char %c\r\nDecimal %d\r\n",a,a);
return 0;
}
2007-01-31 03:12:24
·
answer #2
·
answered by Balk 6
·
0⤊
0⤋
%d means print the numeric value of the variable, %c means print the character representation of the variable. A character, by definition, is represented by one byte in C. For an 8-bit byte, that means that the total number of characters is 256 (an 8-bit byte can range in value from 0-255). In ASCII, the capital letter 'A' has a decimal value of 65. The lower case 'a' has a decimal value of 97.
So what the program does is print the entire character set out.
The output will look like:
the value of 1 is *the value of 2 is*the value of 3 is*...
where an asterisk means an unprintable character in this example. Note that you left a newline character (\n) off the end of your format string, so you'll end up with one long string instead of a list like this:
...
the value of 65 is A
the value of 66 is B
...
2007-01-31 03:02:17
·
answer #3
·
answered by rongee_59 6
·
0⤊
0⤋
As you progress through the for loop, you have two values being printed. Well, the same value, but in different formats. %d prints out the integer value. So the first 'a' will be an integer. %c prints out a character or the ASCII code. As you have originally definted 'a' to be an integer, the %c will simply take this value and convert it to its respective ASCII code.
2007-01-31 03:04:04
·
answer #4
·
answered by Entfusion 3
·
0⤊
0⤋
a corresponding to %d represents the numeric value of the variable
where as a corresponding to %c prints the ASCII code of that number
2007-01-31 06:51:53
·
answer #5
·
answered by Bobby 1
·
0⤊
0⤋
Those correspond to %d and %c. This shows you what each number from 1-254 represent as characters.
2007-01-31 02:49:55
·
answer #6
·
answered by dzr0001 5
·
0⤊
0⤋
Hi there
From what the code says, it outputs what the variable "a" is at that moment during the "for loop".
Hope this helps
2007-01-31 02:45:29
·
answer #7
·
answered by iskai 4
·
0⤊
0⤋