Working on Ubuntu
I have a problem with my code and i dont know how to fix. Maybe there is a function that will help me with that.
I want to input a string and then my program need to check if it is a number from 1 to 1000. If there is a letter or a symbol
Here is my code:
char tab[200]="";
int i;
scanf("%199[^\n]s",tab);
for(i=0;i<200;i++)
{
if(tab[i] >= 'A' && tab[i]<='Z')
{
printf("Big letters\n");
}
else if(tab[i] >= 'a' && tab[i]<='z')
{
printf("Small letters\n");
}
}
if(strlen(tab) == 4 && tab[3] > 0 && tab[2] > 0 && tab[1] > 0 && tab[0] > 1)
{
printf("Bigger then 1k\n");
}
else if(strlen(tab) > 4)
{
printf("Longer then 4 chars\n");
}
It's not working properly and it also doesnt include symbols...
I've found code like this but im not sure how to make my number less then 1001
char input[MAXINPUT] = "";
int length,i;
int number;
printf(" id: \n");
fgets(input, MAXINPUT, stdin);
number = atoi(input);
length = strlen (input);
for (i=0;i<length; i++)
if (!isdigit(input[i]))
{
printf ("Entered input is not a number\n");
exit(1);
} else if (number < 1001)
printf ("Given input is a number\n");
Not sure if i am using fgets
properly here.
Before u will send me to here , please read my question