\"Design a program that prompts the user to enter a string containing multiple s
ID: 3831963 • Letter: #
Question
"Design a program that prompts the user to enter a string containing multiple sentences, and then displays the string with the first character of each sentence capitalized. For instance, if the user enters "hello. my name is Joe. What is your name?" (Hint: the toUpper library function can be used to convert a single character to uppercase.)" Can someone run through this really quick, please?. Also, we're using Raptor so if anyone has any knowledge of that program and can convert the answer for said program I'd really appreciate it.
Explanation / Answer
code:
#include <stdio.h>
#include <ctype.h>
int main()
{
char c;
char str[100];
char final_str[2000];
int i=0;
int k=0;
int flag;
/* Reading each character from given string and terminate once we provide ctrl+d */
while((c=getchar())!=EOF){
str[i++]=c;
/* once the character is '.' it assumes a sentence is passed*/
if(c=='.'){
flag=1;
for(int j=0;j<i;j++){
/* only alphabets are converted to upper case */
if(flag && ((str[j]>='A' && str[j]<='Z')||(str[j]>='a' && str[j]<='z'))){
str[j]=toupper(str[j]);
flag=0;
}
final_str[k++]=str[j];
}
i=0;
}
}
final_str[k]='';
printf(" final string: %s ", final_str);
}
execution run and output
186590cb0725:Chegg bonkv$ ./a.out
knowing how to write a paragraph is incredibly important. it’s a basic aspect of writing, and it is something that everyone should know how to do. there is a specific structure that you have to follow when you’re writing a paragraph.
^D
final string: Knowing how to write a paragraph is incredibly important. It’s a basic aspect of writing, and it is something that everyone should know how to do. There is a specific structure that you have to follow when you’re writing a paragraph.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.