Archived

This topic is now archived and is closed to further replies.

Fractal

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

Recommended Posts

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.

Share this post


Link to post
Share on other sites

  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 Adam

printf ("your name is %s", PlayerName);


-------
Andrew

Share this post


Link to post
Share on other sites