C Write a function that accepts a pointer to a Cstring as an

C++

Write a function that accepts a pointer to a C-string as an argument and capitalizes the first character of each sentence in the string. For instance, if the string argument is “hello. my name is Joe. what is your name?” the function should manipulate the string so it contains “Hello. My name is Joe. What is your name?” Demonstrate the function in a program that asks the user to input a string and then passes it to the function. The modified string should be displayed on the screen.

Solution

#include<iostream>

#include<cctype>

#include<cstdlib>

using namespace standard;

void capitalize(char sentence[], int const SIZE);

int main()

{

const int SIZE = 1024;

char sentence[SIZE];

cout << \"Enter a string: \" << endl << endl;

cin.getline(sentence, SIZE);

capitalize(sentence, SIZE);

system(\"pause\");

return(0);

}

void capitalize(char sentence[], int SIZE)

{

char *strPtr;

int count = 0;

sentence[0] = toupper(sentence[0]);

for (int i = 0; i < SIZE; i++)

{

strPtr = strstr(sentence[i], \".\");

if (*strPtr == \'.\')

{

*strPtr = toupper(*strPtr);

}

}

while (sentence[count] != \'\\0\')

{

cout << sentence[count];

count++;

}

}

C++ Write a function that accepts a pointer to a C-string as an argument and capitalizes the first character of each sentence in the string. For instance, if th
C++ Write a function that accepts a pointer to a C-string as an argument and capitalizes the first character of each sentence in the string. For instance, if th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site