Can anyone tell me what's wrong with this code?
int PlayerName
printf ("\nWhat is your name?\n");
scanf ("%d", &PlayerName); //eg Nick or Adam
printf ("your name is %d", PlayerName);
I''ve included all of the neccessary headers, but the name that is typed in comes out as a number.
- You are defining PlayerName as an integer ( int ). Try defining it as an array of characters.
- Your scanf is using the wrong specifier. Use %s for strings.
- Your printf is also using the wrong specifier. %d is for integers use %s for string.
New code:
char PlayerName[10];printf ("\nWhat is your name?\n");scanf ("%s", PlayerName); //eg Nick or Adamprintf ("your name is %s", PlayerName);
-------
Andrew
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement