My teacher gave us code that Write a function declared as "int categorize(char *str)" which accepts a string as an input parameter and categorize the string. The function should return the category number as decribed below:
Category 1: If the string contains only capital letters (e.g. ABCDEF), the function should return 1.
Category 2: If the string contains only small letters (e.g. abcdef), the function should return 2.
Category 3: If the string contains only letters but no other symbols (e.g. ABCabc), the function should return 3.
Category 4: If the string contains only digits (e.g. 12345), the function should return 4.
Category 5: If the string contains both letters and digits but no other symbols (e.g. Hello123), the function should return 5.
Category 6: Otherwise, the function should return 6.
I write this but not working
#include<stdio.h>
#include<string.h>
// Write your categorize function here
int categorize(char *str) {
int x=0;
while(str[x]!= '\0'){
if((*str>='A'&&*str<='Z') && (*str>='a'&&*str<='z') && (*str>='0'&&*str<='9'))
return 5;
else if((*str>='A'&&*str<='Z') && (*str>='a'&&*str<='z'))
return 3;
if((*str>='A') && (*str<='Z'))
return 1;
else if((*str>='a')&&(*str<='z'))
return 2;
else if((*str>='0')&&(*str<='9'))
return 4;
x++;
}
return 6;
}
///////////////////////////////////////
// Test main()
// DO NOT MODIFY main()
// or your code will not be evaluated
int main() {
char str[100];
scanf("%s",str);
int c = categorize(str);
printf("%d\n",c);
return 0;
}
///////////////////////////////////////