Thread: I need help excluding symbols for name input

  1. #1
    Registered User
    Join Date
    Oct 2012

    I need help excluding symbols for name input

    So my friend is trying to teach my how to program in C and I'm stumped. I'm a complete beginner and he gave me something to try and do with more advanced code than what I know and understand. For what I have to do with his code he told me that I need to exclude certain characters, specifically periods and commas from names, and only allow the numbers 1 or 2 to be put in at the end of a name. So for example Josh1 would be allowed, but Josh,2 wouln't be. Is there a way I can do this? I've inserted the code below and need the help.

    //headers included
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    //char arrays to hold playernames and int values for various things.
    int balloons,lp,cp,playonce,check;
    char player[2][10];
    char first[10];
    //Main Function
    int main (void)
        while (balloons != 0)
            printf("There Are %d Balloons Left\n",balloons);
    //SetUp Function That Sets base Peramators and gets the players names.
    int SetupGame (void)
        balloons = 10;
        if (playonce == 0)
            //Gets Players Names
            printf("Welcome to Balloon pop\nFirst Player Enter Your Name:\n");
                printf("Welcome to Balloon pop\nSecond Player Enter Your Name\n");
                //Checks If The Names Are The Same.,
                if (!(strcmp(player[1], player[0])))
                    check = 1;
            while(check != 1);
            playonce = 1;
    This is just the piece of coding he told me that I'd need to edit, and I really appreciate the help if it can be given. I'm all out of ideas and so is he(I'm not sure if he's just lying that he doesn't know what to do, or if he's telling the truth that he doesn't).

  2. #2
    Registered User
    Join Date
    Sep 2006
    Tell your friend, he's all wet. Click on the C Tutorial button at the top of this forum, and work through it slowly and thoroughly.

    You'll learn BOATLOADS more than by messing with the 10 Balloons Game.
    Hint: to win, go first, and always leave after your move, an odd number of Balloons. Eventually that number will reduce to 3 balloons, and then your opponent will make his last move. You win on the next move, since there will be either one or two balloons left.

    Anyway, go through the C tutorial, and worry about game programs MUCH later. There are lots of little subtleties to even simple games like this.

    Good luck!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner: Copy from 1 file to another, excluding spaces.
    By RyanLeonard in forum C Programming
    Replies: 5
    Last Post: 10-27-2010, 09:37 AM
  2. excluding characters
    By xniinja in forum C Programming
    Replies: 18
    Last Post: 07-08-2010, 11:55 AM
  3. Replies: 1
    Last Post: 12-10-2008, 11:29 AM
  4. symbols, no symbols, symbols ...
    By pavmarc in forum Linux Programming
    Replies: 0
    Last Post: 08-23-2005, 12:36 PM
  5. 3 struct variables excluding '/'
    By xion in forum C++ Programming
    Replies: 3
    Last Post: 04-07-2004, 06:32 AM