I have this C code. If I input a LOL123 it should display that it is uppercase. And lol123 it is in lowercase. How do I use isalpha in excluding non-numerical input when checking isupper or is lower?
#include <stdio.h>
#define SIZE 6
char input[50];
int my_isupper(char string[]);
int main(){
char input[] = "LOL123";
int m;
m= isupper(input);
if( m==1){
printf("%s is all uppercase.\n", input);
}else
printf("%s is not all uppercase.\n", input);
return 0;
}
int my_isupper(char string[]){
int a,d;
for (a=0; a<SIZE); a++){
d= isupper(string[a]) ;
}
if(d != 0)
d=1;
return d;
}
Fairly simple:
For upper-case function just loop trough the string and if a lowercase character is encountred you return
false
like value. And don't use standard library functions names to name your own functions. UseisUpperCase
instead.Live Demo: https://eval.in/93429
You have a lot to learn, besides using a name of a standard function your design also is completely flawed. You only memorize the case of the last character that you encounter in your
for
loop, so the result that you return is not at all what you think.Some more observations:
isupper
to be a logical value. Testing that again with==1
makes not much sense.input
, one in file scope, one inmain
.