Zelaron Gaming Forum

Zelaron Gaming Forum (http://zelaron.com/forum/index.php)
-   Tech Help (http://zelaron.com/forum/forumdisplay.php?f=329)
-   -   C programming Count uppercase letters in a sentence (http://zelaron.com/forum/showthread.php?t=33903)

deadlock75 2004-10-15 09:35 PM

C programming Count uppercase letters in a sentence
 
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

Quote:

Originally Posted by deadlock75
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.

PHP Code:

#include <stdio.h>

int main(void)
{
     
char string[50];
     
gets(string);
     
int count 0;
     
int i;
     for(
0string[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

Quote:

Originally Posted by WetWired
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
Code:

i<string[i]
I meant to just say
Code:

string[i]
I'll go ahead and change that.

But yea, WW's method is better. Use strlen.


All times are GMT -6. The time now is 09:33 AM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.