Answer to Question #165388 in C++ for Jamal

Question #165388

I have a boolean function that is checking a string for non alphanumeric characters. I managed to get it to work but I can not use the string outside of the function with the the non alphanumeric characters removed and I cannot figure out why. When i try to output the string to a file from within the function it only inputs the last character.


1
Expert's answer
2021-02-21T19:53:19-0500
#include <iostream>
using namespace std;

int main()
{
    //1
    char str[100];

    //2
    cout << "Enter a string to test :" << endl;
    cin.get(str, 100);

    //3
    for (int i = 0; str[i] != '\0'; i++)
    {
        //4
        if (!isalnum(str[i]))
        {
            cout << str[i] << " is not alphanumeric" << endl;
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment