hi everyone :)
what i'm trying to do is to check if word in a string has numbers in it
for example:
if i enter string of one word "he11o"
i want to show error message that says
"One or more characters are numeric! Please re-enter the word!"
and if every character is alphabetic i want to let program continue working(this is just a small part of my overall program.) i have no idea how to check each character, please help.
i'm working in DevC++ if that matters
my overall program is about converting NOUN words to PLURALS
i have everything done! this is the only part i cant find solution to :(

5 Years
Discussion Span
Last Post by nullptr

I have tried this but still not working, it keeps looping even if there is no numbers in the word.
i've tried word (hello) and it's not working.

string word;
  int i = 0;
  while (word[i])
        if (isalnum(word[i]))
              cout<<"One or more characters are not alphabetic, please enter another word! \n";

You've got if (isalnum(word[i])), which basically means if word[i] is either a letter of the alphabet or numeric, you're failing it.
What you want to do is contained in Moschops reply. Check whether isalpha(word[i]) is false.
Also, when you get the new word on failure, you're not resetting i and you'd also want to use continue; after that so that you skip the i++ at line 12.

Edited by nullptr: added content

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.