Question
How to declare a string variable in C?
Background
In my search, to learn the basics of c , I try to transfer one of my old python , Bob , to C. In the program, the script asks the user for information about himself, and then spits out the answers. Almost all of these variables use raw_input for their information - the variables are strings. But I did not find a way to declare C variables.
code
So far, I have been trying to declare a variable of type char and int. Here is the code, switch the type at your leisure.
int main(int argc, const char * argv[]) { int name; printf("What is your name?"); scanf("%s",&name); printf("Your name is %s", name ); return 0; }
Error message
When I run this code, Xcode returns some strange things. This part of globidty-gloop is highlighted.
0x7fff96d2b4f0: pcmpeqb(%rdi), %xmm0
Lasty, this Yahoo answer said that I had to use something called character array . This was published 5 years ago, so I suggested that there is a better way.
EDIT
I follow the C Programming Guide.
source share