473,394 Members | 2,020 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,394 software developers and data experts.

C: How to check if the float is not a char?

6
Hello again,

I would like to ask how could I check if the input is right:
the program asks user to input a float from a keybord, but what if user inputs a char. Is there any funcion which can check that?

Thanks in advance.
Apr 6 '08 #1
3 8008
questionit
553 512MB
Hello again,

I would like to ask how could I check if the input is right:
the program asks user to input a float from a keybord, but what if user inputs a char. Is there any funcion which can check that?

Thanks in advance.
Hi

You can use library function ischar() if you are using C to check if the input is a character or a quoted string. ischar returns TRUE if input was char , FALSE otherwise.

Manual method of doing it is this:
Expand|Select|Wrap|Line Numbers
  1.   while(scanf("%f", &myFloatVal) == 0) 
  2.    printf("Invalid input, enter again");
  3.  
On success, the scanf() function returns the number of items succesfully read.
0 means no successful input (float in this example) is read.

Regards
Qi
Apr 6 '08 #2
dewi44
1
<code snipped>
Nov 7 '08 #3
Banfa
9,065 Expert Mod 8TB
dewi44: I have removed you coded not only do we not allow posting of full code solutions and it didn't compile as either C or C++ and it was logically incorrect (after you fix the compilation errors try entering the strings "3.5,5" "3.55").

Please read the posting guidelines, paying particular attention to Help on posting coursework questions and answers.. Please do not post full code solutions.

Banfa
Administrator
Nov 7 '08 #4

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

Similar topics

4
by: JC | last post by:
hi i want to check a char in the char array public void characters(char chars, int start, int length) { if (chars!='/n' || chars((char)'/r')) { System.out.println("String read is " + new...
18
by: muser | last post by:
is string converted to its integer equivalent by minusing it by 48? the function is suppose to check the fifth digit of struct member using the formula contained within the function. The function...
6
by: Andrej Prsa | last post by:
Hi! Is there a way to reliably test whether a string was ever declared? E.g. char *str; test (str); /* -> no */ str = strdup ("contents"); test (str); /* -> yes */
6
by: Peter Dunker | last post by:
Hello, I think I have a newbee question. If I create a char pointer at the beginning of function and use it only in a special case: char *name; if (a = 1)
9
by: Gregory.A.Book | last post by:
I am interested in converting sets of 4 bytes to floats in C++. I have a library that reads image data and returns the data as an array of unsigned chars. The image data is stored as 4-byte floats....
3
by: begum | last post by:
hi everybody; I wirte a program but i have some problem. When I enter character or negative number, the program is crashed.I want it to give me a output like that " you will enter character or...
3
by: docmur | last post by:
Okay heres my problem I have a problem called Calc which the user enters 2 numbers and a sign to be done with what is entered EX: ./calc 200 + 200 or ./calc 200.20 + 200 Okay thats easy...
5
by: Travis | last post by:
I am using a function that returns a const char * that is usually a word, etc. How can I check to see if what it returns is empty? I tried if (function() == "") and (function() == NULL) and...
9
by: popamit60 | last post by:
Tell me Guys , If there is any Fun to check float numbers in javascript ?? Tell me d solution Thanks Amit
2
by: jeyshree | last post by:
please explain me the size of int ,float.,char,double,and pointers in 16 and 32 bit
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.