I want it on C Write a program that reads a string from the user. It then capita
ID: 3720073 • Letter: I
Question
I want it on CWrite a program that reads a string from the user. It then capitalizes the first letter of each word. Finally, the program displays the new string. The program must use a pointer to the input string for all the required tasks: reading, capitalization, and display.
I want it on C
Write a program that reads a string from the user. It then capitalizes the first letter of each word. Finally, the program displays the new string. The program must use a pointer to the input string for all the required tasks: reading, capitalization, and display.
I want it on C
Write a program that reads a string from the user. It then capitalizes the first letter of each word. Finally, the program displays the new string. The program must use a pointer to the input string for all the required tasks: reading, capitalization, and display.
Explanation / Answer
#include <stdio.h>
#include <string.h>
int main()
{
char *str; /* Declare str as pointer to char */
int i=0; /* Keep track the location of character in string */
printf("Enter the String:");
gets(str); /* gets() function take input string including white space */
while(*(str+i)!='') /*loop executed until '' null character not found*/
{
if(i == 0)
*(str+i) = toupper(*(str+i)); /* converting into capital letter for first word */
if(*(str+i)==' ')
*(str+i+1) = toupper(*(str+i+1)); /* converting into capital letter for word's found after white space*/
i++;
}
printf("The new string:%s",str); /* Printing new string */
return 1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.