I’m trying to write a function that is able to determine whether a string contains a real or an integer value.
This is the simplest solution I could think of:
int containsStringAnInt(char* strg){ for (int i =0; i < strlen(strg); i++) {if (strg[i]=='.') return 0;} return 1; }
But this solution is really slow when the string is long… Any optimization suggestions? Any help would really be appreciated!
You are using strlen, which means you are not worried about unicode. In that case why to use strlen or strchr, just check for ‘\0’ (Null char)
Only one parsing through the string, than parsing through the string in each iteration of the loop.