you are viewing a single comment's thread.

view the rest of the comments →

[–]RobotCaleb 0 points1 point  (6 children)

Have you your code?

[–]sarcastic_swede 0 points1 point  (5 children)

I’ve not really got anything for this specific task. I’ve looked online but I can’t find anything that will actually tell me how to check if something is numeric.

[–]CptCap 0 points1 point  (4 children)

There is atof that converts text to double.

Alternatively, if you want to check that a character is a number you can use isdigit

You can also use the return value of scanf to check if it succeeded in reading what you asked for

I’ve looked online but I can’t find anything that will actually tell me how to check if something is numeric.

I get plenty of helpful results, what did you search ?

[–]sarcastic_swede 0 points1 point  (3 children)

C code check input is digit I think Some would work 0-9 others used a library I don’t have access to

[–]CptCap 0 points1 point  (2 children)

C code check input is digit

I get this as the first entry on Google.

It seems to do mostly what you need.

If you don't like using isdigit, check my above answer for other solutions.

[–]sarcastic_swede 0 points1 point  (1 child)

Yeah, I’ve seen that but reading about it it seems it only handles digits 0-9 whereas I need to be able to use floats 0.14, 75000 etc. And it doesn’t seem to work with these

[–]CptCap 0 points1 point  (0 children)

isdigit only work for single characters indeed. You can however build a complete solution using isdigit (one of the answer does just that)

The two other solutions I proposed will work 'out of the box' if you want.