473,246 Members | 1,521 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,246 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 7978
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...

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.