View Full Version : C programming Count uppercase letters in a sentence
deadlock75
2004-10-15, 09:35 PM
I don't know where to start or how to write the program I need some help I am trying to program an uppercase character is an character whose ASCII value is between 65(A) and 90(Z). I need to write a program that prompts the user to enter a string from the keyboard and will count the number uppercase character and replace each uppercase character by the corresponding lowercase character.
Demosthenes
2004-10-16, 05:41 AM
I don't know where to start or how to write the program I need some help I am trying to program an uppercase character is an character whose ASCII value is between 65(A) and 90(Z). I need to write a program that prompts the user to enter a string from the keyboard and will count the number uppercase character and replace each uppercase character by the corresponding lowercase character.
#include <stdio.h>
int main(void)
{
char string[50];
gets(string);
int count = 0;
int i;
for(i = 0; string[i]; i++)
{
if(string[i] >= 'A' && string[i] <= 'Z')
{
count++;
}
}
printf("%d", count);
}
WetWired
2004-10-16, 11:55 AM
Actually, it would be
for(i=0;i<strlen(string);i++)
not
for(i=0;i<string[i];i++)
Demosthenes
2004-10-16, 11:56 AM
Actually, it would be
for(i=0;i<strlen(string);i++)
not
for(i=0;i<string[i];i++)
Actually, I don't even know why I did
i<string[i]
I meant to just say string[i]
I'll go ahead and change that.
But yea, WW's method is better. Use strlen.
vBulletin® v3.8.2, Copyright ©2000-2025, Jelsoft Enterprises Ltd.