Hi I've a string input and I have to parse it in such a way that that there can be only white space till a digit is reached and once a digit is reached, there can be only digits or white space till the string ends. Am I doing this correctly ? Thsi is just a begining :
I want to actually convert a string to unsigned long. So this kind of algorithm should be carried out prior to strtoul function to ensure that some of the weakness from which the strtoul function suffers like convertin 123aaaaa to 123 for eg or -123 to some unsigned value is removed. This will also ensure that when you have a string like :Code:#include <stdio.h> #include <string.h> int main(void) { char s[50]; int i = 0; gets(s); while (isspace(s[i])) i++; while (isdigit(s[i])) i++; while (isspace(s[i])) i++; if (s[i] != '\0') printf("\nstring can't be converted\n"); return (0); }
1234 78
1234 is not returned but an error message will be printed. Because a string should only contain 1 number
I'm also working on a function for doubles i.e. representing them in exponential format.



LinkBack URL
About LinkBacks



