Almost there

This is a discussion on Almost there within the C++ Programming forums, part of the General Programming Boards category; Ok I seem to have all the loops in place and somewhat working and I found in other threads good ...

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

    Unhappy Almost there

    Ok I seem to have all the loops in place and somewhat working
    and I found in other threads good info on actually checking to see if its a palindrome. But what is wrong with this loop?

    while(infile) //files already open and I have two arrays, input,test
    {
    infile.getline(input,MAX) // MAX=50
    for(int index=0;index<MAX;index++)
    input[index]=tolower(input[index]; // to lower case

    for(int index2=0;index2<MAX;index2++)
    {
    if(isalpha(input[index2])) // checks if its a letter
    {
    test[counter]=input[index2];
    counter ++;
    }
    }


    My thinking on the if statement is it will check input[0] and if its a letter it will assign test counter[0] to the letter in input[0] and if its not it should fall through and go to input[1].

    OK heres the problem if I run A@bbA through it , it outputs
    abbabba

    I think its something to do with if statement ??
    Thanks for the help

  2. #2
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    Doesn't tolower () return a null-terminated string (not a single char)?
    MSVC++ 6.0

  3. #3
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    .

Popular pages Recent additions subscribe to a feed

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