473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Error check in C when a char has been entered intead of an int?

How can i check and creat a loop for the error in which a char has been entered by user insted of an int input!!!!??
Im new to C, so please keep it simple!!!!!!Tanx
Feb 16 '08 #1
8 3031
sicarie
4,677 Expert Mod 4TB
I'd use a while loop, you can test the ASCII value, but it mostly depends on who you plan on reading it in.
Feb 16 '08 #2
I'd use a while loop, you can test the ASCII value, but it mostly depends on who you plan on reading it in.
I just suppose to get 3 int numbers as 3 sides of a triangle. So I cant allow the user to enter any char or decimals. So is the ASCII valuse a good choice in a while loop or not ( in error checking)?
Feb 16 '08 #3
sicarie
4,677 Expert Mod 4TB
I would recommend reading a value in as a char, then comparing that. You can use the char value, or convert it if you want. That, encompassed in a while, will probably do it.
Feb 16 '08 #4
i can do that. But there is a problrm.
what if a side of triangle be greater than 9. for example 123, 321, 32. Then what?
Feb 16 '08 #5
i can do that. But there is a problrm.
what if a side of triangle be greater than 9. for example 123, 321, 32. Then what?

Hi ,
There are multiple way to solve ur problem.
1.check the return status of the scanf function and can conclude it.
2.get number as string and verify it then convert it to int.
3.get chars one by one then parese it and pass it to you program.
Regards,
Arul
Feb 16 '08 #6
Hi ,
There are multiple way to solve ur problem.
1.check the return status of the scanf function and can conclude it.
2.get number as string and verify it then convert it to int.
3.get chars one by one then parese it and pass it to you program.
Regards,
Arul
So i will get the int numbers in a string.....check to see if they are char or nor then convert them into int ...right????!!!
Feb 16 '08 #7
sicarie
4,677 Expert Mod 4TB
I think this thread might help you get a better idea of one method you can use.
Feb 16 '08 #8
So i will get the int numbers in a string.....check to see if they are char or nor then convert them into int ...right????!!!
yes, also can go with scanf return val
Feb 16 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Raquel | last post by:
Following is a simple trigger definition: CREATE TRIGGER TRIG_EMPLOYEE_1 AFTER UPDATE OF SALARY ON DB2ADMIN.EMPLOYEE FOR EACH STATEMENT MODE DB2SQL CALL DB2ADMIN.SQLSP10( ) This gives an...
1
by: Del | last post by:
We have a MS SQL Server 2000 application for our shipping system. We have created a front end application using MS Access for our order analyst. The front end application allows the analyst to...
5
by: hpy_awad | last post by:
I wrote that example from a book and there is en error in the display module that it does not showing all the records are entered in the input module. I traced with some printf statments without...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
9
by: i | last post by:
#include<stdio.h> #include<conio.h> #include<process.h> #include<string.h> char ch; int n,m; void main(); char check(int,int,char); void cash(int,int,char); void debit_card(int,int,char);
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
2
by: vijayrvs | last post by:
SearchCrawler.java The program search crawler used to search the files from the website. From the following program i got 7 compiler error. can any body clarify it and provide me solution. ...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.