C Programming Help I am writing a program that will ask a user to Enter Amount o
ID: 3730274 • Letter: C
Question
C Programming Help
I am writing a program that will ask a user to Enter Amount of Sentences
The user will enter no more than 100 characters for every sentence
After I will convert every sentence to uppercase, with and without whitespace
This part is easy, I was able to to that
My problem is I want to be able to collect characters from ALL SENTENCES and display TOTAL characters, with and without whitespace
Example:
Hello My name is John
I am very nice
I am going to the park
Total Characters for all sentences: 89
Total Characters without whitespace: 84
-------------------------------------------------------------
//convert.c
void convertSentence(char *sentence) {
int i=0;
while(sentence[i] != '')
{
sentence[i] = toupper(sentence[i]);
i++;
} }
void convertAll(char **sentenceList, int numOfSentences)
{
int i = 0;
while(i < numOfSentences)
{
convertSentence(sentenceList[i]);
i++;
} }
Explanation / Answer
You can do like this to count characters:
void convertSentence(char *sentence, int *total, int *white) {
int i=0;
char c;
while(sentence[i] != '')
{
c = sentence[i];
*total = *total + 1; // increasign total
if(c == ' ')
*white = *white + 1; // increasign white space
sentence[i] = toupper(c);
i++;
} }
void convertAll(char **sentenceList, int numOfSentences)
{
int i = 0;
int total = 0;// count of all characters accross all strings
int white = 0;// count of white spaces characters accross all strings
while(i < numOfSentences)
{
convertSentence(sentenceList[i], &total, &white);
i++;
} }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.