Why when I enter "Hello","World","Good", etc it must show 2 ? Why 2 not the other number ?
This is just because it is invoking Undefined Behavior. You will get anything. Sometimes it will give your desired output. Sometimes it will give my desired output. Sometimes it will give no one's desired output.
If I want to scanf string and printf ASCII code of it how should i do ?
Use getchar
function to read your string 'character by character' and then print the ASCII value of each character using %d
specifier.
#include <stdio.h>
int main()
{
char name;
while((name = getchar()) != '\n')
printf("%c\t%d\n",name,name);
}
NOTE: See, in my code I have not used array to store the string. Your string could be of any length.