Thread: Character Array comparison

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    45

    Character Array comparison

    I was wondering how I would go about checking a character array for a specific character that keeps changing.

    What I want to do is compare the User input to the string. If the user does not pick one of the 6 letters, then they are prompted to do so again.
    Code:
    int i, j;
    char Scenario[6]= {'A','B','C','D','E','F'};
    char UserScenario='Z';
    
    
    	while(UserScenario!=TGnScenario[i]) /*Obviously not right, but basically what I need, but how would I go about doing this?*/
    	{
    		printf("TGn scenario (A to F)?\t");
    		scanf("%c", &UserScenario);
    	}
    I was thinking about using something like strchr, but my program ended up not doing anything. I don't know if it applies to this situation since I am comparing a character array, not really a string. This is probably really easy, but I am stuck on it.
    Last edited by magda3227; 07-08-2008 at 07:53 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using a character array in a switch question.
    By bajanElf in forum C Programming
    Replies: 10
    Last Post: 11-08-2008, 08:06 AM
  2. Replies: 7
    Last Post: 05-11-2008, 10:57 AM
  3. Initialzing a 2D character array
    By mike_g in forum C Programming
    Replies: 3
    Last Post: 08-16-2007, 02:05 AM
  4. Character Array - almost? works
    By voltson4 in forum C Programming
    Replies: 3
    Last Post: 03-04-2003, 06:03 PM
  5. Array of Character Arrays
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 02-09-2002, 06:07 PM

Tags for this Thread