I am learning C language. This is my code run in linux.
#include <stdio.h>
int main(int argc, char *argv[]){
char string[] = "Rudolph is 12 years old";
char str[20] = {0}
char i;
sscanf(string, "%s %*s %d", str, &i);
printf("%s -> %dn", str, i);
return 0;
}
My expected result is:
Rudolph -> 12
But I got the result:
-> 12
I want to know what happened and why?
I try to change char i to int i
than I got expected result
But I don’t known why char i can’t let me get expected result.
New contributor
BKHOME is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.