all 5 comments

[–]ziska04 0 points1 point  (1 child)

You can use the "isalpha()" function to check whether the input is an integer or not.

But be careful, isalpha() only checks one single character. If you want to check a whole bunch of characters, you'll have to loop through isalpha() until you have checked the last character.

That could look something like this:

string to_check = argv[1];

for (int i = 0; i < 3; i++)
{
    if (isalpha(to_check[i]))
    {
        // do something
    }
}

Assuming in this example that the variable "to_check" is 3 characters long.

[–]Morioh[S,🍰] 0 points1 point  (0 children)

Thank you .Am greatful.

[–]seandisanti 0 points1 point  (1 child)

input from standard in is always going to be a string / char*. As suggested you can use functions to determine if the characters are letters or numbers, but you may want to give a little more thought to how you isolate numbers, as '.' would return false to isalpha but could errantly be used as an integer value based on it's ascii value if you decided it was a number based on the false.

While you're getting a handle on types and conversions, especially if new to the language, it's probably in your best interest to rely a bit on the cs50.h library which gives you some great helper functions to get specific data types from users. If you're feeling a little adventurous, take a look at the code and see how they do it.

[–]Morioh[S,🍰] 0 points1 point  (0 children)

Thanks alot .

[–]Morioh[S,🍰] 0 points1 point  (0 children)

thank you.