Thread: print player's name

  1. #1
    Registered User
    Join Date
    May 2015
    Posts
    7

    print player's name

    Hello. i am very new in c programming. my friend and i have been asked to do some game. our problem is we don't know how to make the program repeat the player's name after the program asked the player to enter their name. can someone help us.. thank you

  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    First you have to set up the compiler, if it ready then you can use functions like printf and scanf to read the input from the keyboard and print it on the screen.

  3. #3
    Registered User
    Join Date
    May 2015
    Posts
    3
    You can use gets()

    Code:
    int main()
    {
        char Name[10];
        printf("Enter your name: ");
        gets(Name);
        printf("\nWelcome %s!", Name);
        return 0;
    }

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by vssabbathi View Post
    You can use gets()
    Read the FAQ before answering questions

    FAQ > Why gets() is bad / Buffer Overflows - Cprogramming.com

    FAQ > Get a line of text from the user/keyboard (C) - Cprogramming.com
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    May 2015
    Posts
    7
    thank you but i still can't run our game program. it should be when player enter "S" the game ask to enter player name then after the player enter their name the game repeat the player to welcome it then the game should be start but it not. can someone help me to fix it..
    else if(choice=='S'){
    system("cls");


    printf("Enter your name:");
    gets(Name);
    printf("\nWelcome %s!", Name);

  6. #6
    Registered User
    Join Date
    May 2015
    Posts
    7
    thank you.. the code is working but after the game repeat the player name the game's question did not start. can u help me..
    else if(choice=='S'){
    system("cls");


    printf("Enter your name:");
    gets(Name);
    printf("\nWelcome %s!", Name);

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Post the smallest and simplest program that you expect should compile and run as expected, but which demonstrates the problem.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 06-13-2012, 12:34 PM
  2. Replies: 10
    Last Post: 02-19-2010, 07:50 PM
  3. Is it a watch? Is it an MP3 player? Is it a video player?
    By twomers in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 08-15-2006, 10:54 PM
  4. Replies: 0
    Last Post: 03-28-2003, 08:20 AM
  5. wave player or mp3 player using C
    By lliero in forum C Programming
    Replies: 5
    Last Post: 02-27-2002, 11:33 AM