# sentence capitalizer



## karen_CSE (Jul 19, 2005)

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, and that after each stopping punctuation (a period) I would capitalizer the first non-space character. But I have no idea how to translate this to code.


```
//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
}
```
what do I do now?


----------



## LoneWolf071 (Nov 10, 2004)

Think Out Side The Box, Or Draw Something To Make It Easier To Make... I Got All This Done In 10 Minutes? 

```
#include <iostream.h>
#include <stdio.h>
//using namespace std;

//function Prototype
char *Capitalizer(char *);

int main()
{
	char *newline,line[1001]; //That's A Big Buffer, It Might Be TOO Big... Careful There...

	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);
	newline = Capitalizer(line);
	cout << "\nThis is how you should have done it: \n";
	
	cout << newline;
	cout << endl;
}

char *Capitalizer(char *sentencePrt)
{
	int i = 0, j;
		
	if(sentencePrt[i] > 97 && sentencePrt[i] < 112)
	{
		sentencePrt[i] -= 32;
	}
	
	for(i = 0; i < strlen(sentencePrt); i++)
	{
		j = i;
		
		if(sentencePrt[i] == '.' || sentencePrt[i] == '?' || sentencePrt[i] == '!' || sentencePrt[i] == ',')
		{
			j++;
			
			if(sentencePrt[j] == ' ' || sentencePrt == NULL || sentencePrt == '\0')
			{
				j++;
				
			}
			if((sentencePrt[j] > 97 && sentencePrt[j] < 112))
			{
				sentencePrt[j] -= 32;
			}
		}
	}
	//cout << sentencePrt;
	return sentencePrt;
}
```


----------



## karen_CSE (Jul 19, 2005)

hi, 
Ok, I just read your code and I have no idea what #'s 97, 112, and 32 mean. 
1) what does this statement do? "sentencePrt_ -= 32;"
2) How did you get it capitalized without the toupper function? 
3) why did you declare j=i?
4) why did we have to let Capitalizer() = newline? 

one last question, are these really dumb questions? -razz: 

karen_


----------



## LoneWolf071 (Nov 10, 2004)

Check Out www.asciitable.com and you will see...
1. sorry, old programming trick... If You Look At The ASCII Chart, A Capital Letter Is 32 less then a lowercase number, but tit's the same as the toupper or tolower function.

2.Stated In Answer 1.

3. So I Could See If They Put A Space After The Punctuation... 

4.So We Could Pass Along The Sentence And Also Get One Back...

No, Programming is the essence of questioning and answers... but i am getting concerned with how much you are posting and i know myself that i give you the answers, but i think that the questions should be more specific, like how would i do this, not just post the code and have us finish it...


----------



## karen_CSE (Jul 19, 2005)

I'm so sorry that's I'm such a burden to you all. seriously. Don't be modest. I know I am.
But that's the thing. I have no idea how to start with the code. I have the general idea how it should be (like I should use the "for" loop, or use the "strcat" function) but I don't know how to put them together so that it becomes proper coding language. And my book is hecka frustrating. It gives really easy examples, and the HW questions are just way over-the-top. and I'm a visual person; therefore, I need examples to follow. BTW, my textbook's title is "Starting out with C++," can you suggest any other good C++ book that can help me learn?
Besides, I'm taking this class in the summer session at my college. So the three-month workload was shortened to 6 weeks! And I'm a brand-new programming beginner, too! My teacher is so mean, he didn't cut out any HW questions, projects or anything.

Again, I apologize for the load of questions I've been flooding on this site. This week is my final week and all HW and projects (and the final) have to be done by Thursday (which is 2 days away!); that's why I've been asking for so much help. I'm not making excuses or anything. I just thought you deserve the explanation since you've helped me so much. 

Karen


----------



## ricer333 (Sep 17, 2004)

*Books*

karen,
I can recommend the Osborne (author) the Complete Reference C++ (they also make C and Java books) You can find these in any book store (barnes & noble for example) They come with a very in depth knowledge base of the language, how to use things, great index (so when you don't know how to look up something, quick reference and there it is). They also have some great coding examples in there, and out online which you have access to once you purchase the book (basically it's the code examples in the book, but online, so you don't have to type them in, if you want to use them). I would start there.

The best thing I can say is go to your local bookstore, go to the technology section and pick out a couple of books. Thumb through them and see what works best for you! Everyone is different, what is one good book is another person's paperweight!


----------



## tgo (Jul 5, 2005)

too bad c++ doesnt have ucwords because then you could do those program in one line. got to love php and its 1000 built-in functions.


----------



## karen_CSE (Jul 19, 2005)

thanks, richer333 for the recommendation. There are so many books out there that it's hard to pick one out.

and tgo, I...uh...have no idea what you're talking about...sorry...I'm really new to this computer languages thing.

Karen


----------

