need help with a small bug

This is a discussion on need help with a small bug within the C Programming forums, part of the General Programming Boards category; Ok, I know how the palindrome program works. I did it earlier this year, and now the teacher wants it ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,498
    > 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, 01: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21