0

it takes me really long time to figure this out and am not making any progress so i was wondering if someone could help.

how do i use, for example, isalpha in if statement. like:

    if ( argc != 2 || isalpha(argv[1])
{
return 1;
}

what i want is to isalpha check if argv[1] are characters and not numbers and if its not characters i want to make return 1; go through. writing it like this:

  string key = argv[1]; 
   if (argc != 2 || isalpha(key)
  { 
    return 1; 
  }

is not helping. now typing ! before isalpha is not helping either. is it possible to use isalpha and other similiar functions(isdigit) like this or not? thanks

2 Answers 2

1

isalpha() takes a single character. When you try to jam a complete string down its throat, it chokes and coughs up a seg fault. You need to loop through the string and test each char individually.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Also, each of your statements is missing a closing parenthesis ).
    – Cliff B
    Aug 25, 2016 at 19:08
0

for (int i = 0, j = strlen(key); i < j; i ++)

    {
         if (!isalpha(key[i]))
        return 1;
    }

ok, it works like this. thank you

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .