P
pereges
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 ? :
Code:
#include <stdio.h>
#include <string.h>
int main(void)
{
char s[50];
int i = 0;
gets(s);
while (isspace(s))
i++;
while (isdigit(s))
i++;
while (isspace(s))
i++;
if (s != '\0')
printf("\nIncorrect string\n");
return (0);
}
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 :
1234 78
1234 is not returned but an error message will be printed. Because a
string should only contain 1 number in my program.
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 ? :
Code:
#include <stdio.h>
#include <string.h>
int main(void)
{
char s[50];
int i = 0;
gets(s);
while (isspace(s))
i++;
while (isdigit(s))
i++;
while (isspace(s))
i++;
if (s != '\0')
printf("\nIncorrect string\n");
return (0);
}
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 :
1234 78
1234 is not returned but an error message will be printed. Because a
string should only contain 1 number in my program.