Computer science assignment. (strings)

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 3K views
clook
Messages
32
Reaction score
0
i need a make a program that prompts the user to enter a string, and for it to identify the uppercase characters and replace each uppercase char with the corresponding lowercase character. it also needs to count the character

here's what i have so far:

Code:
#include<stdio.h>
#include<string.h>
main()
{

char
		letter[20];
	  
int uppercount,i;

	uppercount=0;
  		
	printf("Please enter characters:\n");
	gets(letter);

	if(letter[i]>= 'A' && letter[i] <='Z')      
    uppercount++;
	{
		letter[i] = letter[i] - 'A'+ 'a';
   
 }
	printf("%c\n", letter);
	   printf("The number of uppercase letters entered: %d", uppercount);
}

doesn't seem to work as i would like.. what changes should i make?
 
Physics news on Phys.org
Initialize your variables and be aware the the letter in the printf will attempt to print out the address of the array as a character (you need to dereference your array by adding a and put it inside a loop since %c will print (I believe) out one character at a time). You also need some kind of loop to count the uppercase letters.
 
Last edited: