-1
I have to pass to the lowercase function a string and check if the elements of this string are lowercase, if they are must return true, if it is not must return false, however every time I run it accuses as false.
I believe I’m incorrectly using the bool
.
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
/* Devolve verdadeiro se todos os caracteres alfabéticos da
string s passada como parâmetro são caracteres minúsculos. */
bool minusculo(const char * s){
bool ts = true;
int x = strlen(s);
int cont = 0;
int i;
for(i = 0; i < x; i++){
if(isupper(s[i])){
ts = true;
}
else{
ts = false;
}
}
return ts;
}
int main(){
char str[] = "1 exercicio pratico ";
if (minusculo(str)) {
printf("\"%s\" tem todos os caracteres minusculos\n", str);
}
else {
printf("\"%s\" NAO tem todos os caracteres minusculos\n",str);
}
system("pause");
return 0;
}
I figured out where I went wrong, now it’s simpler and more functional.
– lcasa