Thread: need help with a small bug

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    51

    need help with a small bug

    Ok, I know how the palindrome program works. I did it earlier this year, and now the teacher wants it using command line arguments.


    PHP Code:
    int main(int argcchar *argv[])
    {

        
    int lenirun,
        
    match 1;

        if (
    argc 1)
        {
        
    len strlen(argv[1]);
        
    run len/2;

        for( 
    i=0i<runi++ )
        {
            if ( 
    argv[1][i] != argv[i][len-i-1] )
            {
            
    printf("%d:   %c != %c\n"iargv[1][i], argv[1][len-i-1]);
            
    match 0;
            }
            else
            
    printf("%d:   %c == %c\n"iargv[1][i], argv[1][len-i-1]);

        }

        if (
    match)
            
    printf("%s is a palindrome!!!\n\n"argv[1]);
        else
            
    printf("%s is not a palindrome.\n\n"argv[1]);

        }

    I have been working on a project for a few days, and my brain is fried. Can anyone tell me what I have messed up here. If if give call it like "prog abba", it says the a's are not equal, but the b's are. Any ideas?

    Thanks for any help.
    Last edited by drharv; 04-23-2002 at 02:43 PM.

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    51
    also, i apparently don't understand how to use the code tags correctly. how do insert them in my posts?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > if ( argv[1][i] != argv[i][len-i-1] )

    Second one uses 'i' not '1' as the first subscript

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    51
    Thank you very much, I told you my brain was fried.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ATL bug of CComPtr?
    By George2 in forum Windows Programming
    Replies: 6
    Last Post: 04-07-2008, 07:52 AM
  2. want to make this small program...
    By psycho88 in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2005, 02:05 AM
  3. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  4. small bug
    By doublin in forum C++ Programming
    Replies: 6
    Last Post: 10-24-2002, 09:28 AM
  5. yhatzee, small straight
    By uglyjack in forum C++ Programming
    Replies: 2
    Last Post: 06-13-2002, 03:09 AM