Looking around online I didn't find a solution that satisfied me, so I tried it myself. But now in a lecture it was also said that calling functions and waiting for returns might cause the stack to overflow, so is this a bad idea? I use this function to check whether argv[1] is a float or not. Would a loop be better? or is there something way more intuitive? there must be exactly one point and it has to be followed by atleast one digit right?
#include <stdbool.h>
#include <ctype.h>
/**
* checks if string is floating point number
* please call function with pointCounter=0 and digitAfterPoint=false
*/
bool isFloatString(char *s, int pointCounter, bool digitAfterPoint)
{
if (isdigit(*s))
{
if(pointCounter==1)
{
digitAfterPoint=true;
}
return isFloatString(s+1, pointCounter, digitAfterPoint);
}
else if (*s == '.' && pointCounter==0)
{
return isFloatString(s+1, pointCounter+1,digitAfterPoint);
}
else if (*s == '\0' && digitAfterPoint)
{
return true;
}
else
{
return false;
}
}