Thread: need help on string compare

  1. #1
    Unregistered
    Guest

    need help on string compare

    i stumble onto a problem on comparing strings
    can someone help me again? I have manage the checking on the string of input but i cant seem to code the correct part on comparing M and F, its about the gender input. User can only input M,m,F or f.
    PHP Code:
    void val_gen(void)
    {
        
    char msg[]="Invalid Input!!! Accepts only M or F only";
        
    char v_flag;
        do
        {
            
    gotoxy(45,15); clreol();
            
    fflush(stdin);
            
    gets(mem_temp.mem_gen);
            
    v_flag val_gsize(1mem_temp.mem_gen);
            if (
    v_flag =='Y')
            {
                
    v_flag=val_gchar(mem_temp.mem_gen);

                if(
    v_flag=='N')
                
    err_msg(msg);
            }
        }
        while (
    v_flag=='N');
        
    caps_str(mem_temp.mem_gen);


  2. #2
    Unregistered
    Guest
    the code should be like this but i cant seem to know what to be put in, pls help

    PHP Code:

    char val_gchar
    (char text[])
    {
      
    char status;
        

           while (
    text[] != '\0')
               {
            if (((
    strcmp(text[], "m") && strcmp(text[],"f")) ==0)
                
    status 'N';
            else
                
    status ='Y';


  3. #3
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    Code:
    char val_gchar(char text[])
    {
      char status;
      
            if (strcmp(text, "m") != 0 && strcmp(text,"f") != 0)
                status = 'N';
            else
                status ='Y';
    
            return(status);
    }

  4. #4
    Unregistered
    Guest
    can i use the below instead?
    but both the solution given to me seem that the program will perform illegal operation....when i run it

    PHP Code:
    char val_gchar(char text[])
    {
      if (
    strcmp(text"m") !=&& strcmp(text,"f") !=0)
                return 
    'N';
            else
                return 
    'Y';


  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    33
    sorry forgot to log in when writing the code

  6. #6
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    Yes, you can go about that way too.

  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    33
    but i cant execute it when i try running, even with your coding or mine, is there a problem somewhere that i miss it?

  8. #8
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    What's the message? Paste the code.

  9. #9
    Registered User
    Join Date
    May 2002
    Posts
    33
    there is no error, my dos went to illegal operation and prompt to quit
    The program encounter a general protection exception

    fault location 8b50:1004
    iinterupt in service : none.

    this happen only after I add in the validate gender coding...

  10. #10
    Registered User
    Join Date
    May 2002
    Posts
    33
    Thanks,

    I have rewritten my codes, seem fine now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  2. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  3. problems with overloaded '+' again
    By Brain Cell in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2005, 05:13 PM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. "Operator must be a member function..." (Error)
    By Magos in forum C++ Programming
    Replies: 16
    Last Post: 10-28-2002, 02:54 PM