That makes sense - Thanks!!
I applied that to my code shown below. I need to do some tuning.. not working yet. Anything stick out as problem? The only drawback is I will have to reinitialize the variable prior to each while loop right? Any shortcuts I can take on that? Thanks again.
Code:
char hardness[256];
char *first_nonblank;
double hardness2;
int num_spaces = 0;
strcpy(hardness," 23.345");
first_nonblank = hardness;
while (isspace(*first_nonblank))
{
first_nonblank++;
num_spaces++;
}
if (num_spaces==0)
{
hardness2 = atof(first_nonblank);
printf("%1f\n", hardness2);
}
else
{
hardness2 = 0.0;
printf("Error:Hardness test value invalid - not recorded!");
}
/*Next while loop I will have to remember to do num_spaces=0;*/
I just seen your feedback laserlight - Thanks. I will give that a shot. I will just use an if statement right?
Does this look about right?
Code:
char hardness[256];
char *first_nonblank;
double hardness2;
/* int num_spaces = 0; */
strcpy(hardness," 23.345");
first_nonblank = hardness;
if (isspace(*first_nonblank) && isspace(*first_nonblank + 1))
-error-
else if (isspace(*first_nonblank) && !isspace(first_nonblank + 1))
-convert-
else
hardness2 = atof(first_nonblank);
printf("%1f\n", hardness2);