Computer science assignment. (strings)

AI Thread Summary
The program aims to prompt the user for a string, identify uppercase characters, replace them with their lowercase equivalents, and count the uppercase letters. The initial code provided has issues, including the need for variable initialization and the correct use of loops for character processing. It is suggested to implement a loop to iterate through each character in the string for both counting and converting uppercase letters. Additionally, the printf function should reference the array correctly to display the modified string. Properly addressing these points will enhance the program's functionality.
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:

Similar threads

Replies
12
Views
2K
Replies
3
Views
1K
Replies
7
Views
2K
Replies
3
Views
1K
Replies
9
Views
4K
Replies
21
Views
4K
Back
Top