Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Need help with my code

+1 vote
asked Nov 12, 2020 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, 2020 by Rick Rob (140 points)
You need to post your code for someone to better help you.
commented Nov 14, 2020 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, 2020 by LiOS (6,160 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.