• Advertisement

Archived

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

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

This topic is 5977 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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 Adam

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


-------
Andrew

Share this post


Link to post
Share on other sites

  • Advertisement