Thread: Almost there

  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
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    Doesn't tolower () return a null-terminated string (not a single char)?
    Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)

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

Popular pages Recent additions subscribe to a feed