For a school project I am doing we are required to take character input through the command line and convert the character to its ascii value. I would think, therefore, that the line of code:
printf("%d",(int)argv[1]);
would print out 97(ascii for a) if i were to type 'a' as the first command parameter. However, my program is printing out 109, the ascii code for 'm'. Why is this happenning??
neclark2
0
Newbie Poster
Recommended Answers
Jump to Postargv[1] is a string even if you enter a character.
Find the length of the string and use a loop to go through each character.printf( "%d\n", argv[1][i] );
[Edit] That example will display the first character of the string.
printf( "%d\n", (int) argv[1] ); is displaying the …
All 2 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.