Can anyone tell me what's wrong with this code?

Started by
1 comment, last by Fractal 22 years, 6 months ago
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.
Could I be any dumber?(What do you mean, "No"?)
Advertisement

  1. You are defining PlayerName as an integer ( int ). Try defining it as an array of characters.
  2. Your scanf is using the wrong specifier. Use %s for strings.
  3. 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

Thanx
Could I be any dumber?(What do you mean, "No"?)

This topic is closed to new replies.

Advertisement