hi...uh...again,

I know I ask a lot of questions, but I'm really clueless. My HW says I have to write a function that accepts a pointer to a C-string as an argument
and capitalizes that first character of each sentence in the string.

I know the toupper function, but I have no idea how to implement it.

//Program #5 Sentence capitalizer

//write a function that accepts a pointer to a C-string as an argument
//and capitalizes that first character of each sentence in the string.

#include <iostream>
using namespace std;

//function Prototype
void Capitalizer (char *);

int main ()
{
	char line[1001];

	cout << "This program will capitalize the first letter of each sentence.\n";

	cout << "Please enter a phrase of no more than 1000 characters, followed by a period.\n";
	cin.getline(line, 1001);

	cout << "This is how you should have done: \n";
	Capitalizer(line);
	cout << endl;
}

void Capitalizer (char *sentencePrt)
{
	char *s = sentencePtr;

//got stuck, don't know what else to do from here
}

can you guys give me a clue?

Just look at each character in the array in sequence. When you find sentence stopping punctuation, the first non-witespace character after it should be capitalized like so:

a[i] = toupper ( a[i] );

And don't forget to include <cctype>

http://www.mcculloughdesigns.com/blog/c-sentence-case-capitalize-word/345/

However, cases where it fails...

He said, "What is your name?"

Doesn't capitalize the 'w'

It is not so clever and finding case examples such as:-

Dr. 
Mr. 
e.g 
I 
I'm 
I'll

And of course doesn't handle proper nouns, such as names. It could probably be changed to get it reasonably good. And you could build a crude library of proper nouns, though it would be impossible to handle every case.

Edited 6 Years Ago by iamthwee: n/a

This article has been dead for over six months. Start a new discussion instead.