Count The Uppercase Letters In A String | C Programming Example

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

isupper(3) ⁉ You heathen 😉
Thanks for the video 👍

bob_mosavo
Автор

Nice thanks Kevin, make advance C videos, Thanks :
// An alternative method without using any help function

int Uppercase(char *string){
int counter = 0;
while(*string != '\0'){
if(*string >= 'A' && *string <= 'Z'){
++counter;
}
++string;
}
return counter;
}

justcurious
Автор

My comments:
- leave the 'strlen()'-function out, as it is quite needless: the string *IS* terminated by a 0x00, so use that.
- skip the 'if'-clause; if's are costly
- use capitals in variable- and functionnames, instead of underscores (it looks soooo 'Linuxy' you know...)

Here's the core of your 'problem':

char String[] = "Let's go to New York",
*s = String;
int CapitalsCount = 0,
WordsCount = 1;

while (*s != 0) /* or simply (*s), but hey, the one maintaining your code may not be as bright as you...*/
{
CapitalsCount += (isupper(*s) != 0);
WordsCount += (*s == ' ');

s++;
}

printf("Total uppercase letters: %d\n", CapitalsCount);
printf("Total number of words : %d\n", WordsCount);

tjdewolff
Автор

who are you prof I need small help😢 I need code for bubble sort algorithm with 2D array….. Please 😢

GasimSarina