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.
#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;
}
}
}
Comments
Leave a comment