99. Check if the String Numeric or Alphabetic

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>
#include <stdint.h>

void classify_string(const char *str) {
     int i = -1;
    while(*str){
       
        if(*str>47 && *str<57 ){
            if(i==-1 || i==0)
                i=0;
            else{
                printf("MIXED");
                return;
                }
        }
        else if((*str>64 & *str<91) || (*str>96 & *str<123) ){
            if(i==-1 || i==1)
                i=1;
            else{
                printf("MIXED");
                return;
                }
        }
        else{
            printf("MIXED");
            return;
        }
        str++;
    }
    if(i==0)
        printf("NUMERIC");
    if(i==1)
        printf("ALPHABETIC");
}

int main() {
    char str[101];
    fgets(str, sizeof(str), stdin);

    // Remove newline
    uint8_t i = 0;
    while (str[i]) {
        if (str[i] == '\n') {
            str[i] = '\0';
            break;
        }
        i++;
    }

    classify_string(str);
    return 0;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote