-2
I wrote a code to receive a char arrangement and return the amount of uppercase letters, but it’s doing the opposite ( returning the amount of lowercase ) and I don’t know why.
void Questao4 ()
{
//definir dado
char* cadeia ;
cadeia = (char*) malloc( 20* sizeof (char));
int i = 0;
//identificar
printf ( "EXEMPLO0413 - Metodo03 - v1.0\n" );
//declaracao e entrada
do
{
printf ( "Entre com uma cadeia de caracteres ( 0 para sair )\n " );
scanf ( " %c", &cadeia[i]);
fflush (stdin);
getchar();
i++;
}
while ( cadeia[i-1] != '0' );
//saida
printf ( "Na cadeia de caracteres apresentada, ha' [%d] maiusculas !!\n" ,contamaiuscula ( cadeia ) );
}
int contamaiuscula ( char x[])
{
//definir dado
int numerodemaiusculas = 0;
int i = 0;
//contagem de maiusculas
while ( x[i] != '\0')
{
if ( x[i] >= 'A' && x[i] >= 'Z' )
{
numerodemaiusculas ++;
}
i++;
}
return ( numerodemaiusculas );
}
I found...stupid mistake. (x[ i ] <= 'Z')
– Thiagonimo