Need help with my code

+1 vote
asked Nov 12 by Vicent Cotaina Bertó (350 points)
I need to make a program that when the user introduce a character instead of a number it gives a message that indicates to introduce another number, but I dont know how can I do it. Because when I try to introduce a character the program autoends.

2 Answers

0 votes
answered Nov 12 by Rick Rob (140 points)
You need to post your code for someone to better help you.
commented Nov 14 by Ritika Joshi (100 points)
take input in form of string and then determine the ascii value of it,based on the value you will know weather the data provided is number or character , and you can print a message according to it.It will be easier for someone to help, if you could upload your written code.
0 votes
answered Nov 13 by LiOS (5,280 points)

There are a few different ways to check what the user has entered; if it's a character or a number.

1. Use the isalpha() function in the ctype.h system header file

Note that the isalpha() function checks the input is in the alphabet A-Za-z. Therefore non-alphabetic characters such as + will return false.

2. Use the isdigit() function in the ctype.h system header file

To bypass how isalpha() checks the input is in the alphabet meaning characters such as + return false, why not check it's not a digit (0-9) and if returns false, it means it's a character that's either in alphabet or non-alphabetic.

3. Validate the ASCII value is within a character range

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.