I'm learning C and I'm trying to extract a float value from a string, it must be in this kind of format. But when I enter a number in my string it only returns an int, can someone help me? thank you
#include <stdio.h>
float daNum(void);
int main (void)
{
float value = 0;
printf("please enter a value:");
value = daNum();
printf("your value is:%.3f \n", value);
return 0;
}
float daNum(void)
{
char store[121] = {0};
float numba = 0;
int const kInvalInput = -5;
fgets (store, 121, stdin);
if( sscanf (store, "%f", &numba) != 1)
{
numba = kInvalInput;
}
return numba;
}