473,231 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

character array correction

Hi there, everyone! I'm a student studying computer animation. But
alas, in order to graduate I have to take a programming class and it's
kicking my butt. I have two projects left to write (and believe me, to
some of the veterans out there, it'll be a piece of cake) one of which
takes a character array and capitalizes where necessary - eg. begining
of the string, after a period. Names and such aren't taken into
account. Like I said, very beginner level stuff. Still, I am having
trouble with the program flow.

I have a character array set up with a maximum input, and I wrote if
statements for every letter, but only for the first member of the
array.

Using a for loop, how do I generalize whether or not subsequent letters
need to be capitalized. I tried creating a bool variable to tell me
whether or not the letter in question IS a capital, but that's where I
get stuck. I'm not using the string library and I KNOW there is a more
succinct method - but that darn syntax gets me every time.

Any help would be much appreciated!!

~junk

/* fu********@gmail.com */

Feb 28 '06 #1
6 2088
I V
fu********@gmail.com wrote:
I have a character array set up with a maximum input, and I wrote if
statements for every letter, but only for the first member of the
array.
"If statements for every letter"? That sounds odd. Perhaps if you post
your code, that would help us give you more specific advice.
Using a for loop, how do I generalize whether or not subsequent letters
need to be capitalized. I tried creating a bool variable to tell me
whether or not the letter in question IS a capital, but that's where I
get stuck. I'm not using the string library and I KNOW there is a more
succinct method - but that darn syntax gets me every time.


One method to consider is using a flag variable which you can set if
the next letter should be capitalized. Here's some psuedo-code which
should explain what I mean:

if current_char is whitespace:
go on to the next character

if current_char is a letter and should_capitalize_next is set:
replace current_char with a capital

if current_char == '.':
set the should_capitalize_next flag
else:
unset the should_capitalize next flag
Hopefully trying to turn that pseudo-code into actual C++ should help.
Let us know how you get on (particularly if I haven't explained it
clearly, or you have difficulty figuring out how to write the C++
translation of the pseudo-code).

Feb 28 '06 #2
In article <11*********************@i40g2000cwc.googlegroups. com>,
fu********@gmail.com wrote:
Hi there, everyone! I'm a student studying computer animation. But
alas, in order to graduate I have to take a programming class and it's
kicking my butt. I have two projects left to write (and believe me, to
some of the veterans out there, it'll be a piece of cake) one of which
takes a character array and capitalizes where necessary - eg. begining
of the string, after a period. Names and such aren't taken into
account. Like I said, very beginner level stuff. Still, I am having
trouble with the program flow.

I have a character array set up with a maximum input, and I wrote if
statements for every letter, but only for the first member of the
array.

Using a for loop, how do I generalize whether or not subsequent letters
need to be capitalized. I tried creating a bool variable to tell me
whether or not the letter in question IS a capital, but that's where I
get stuck. I'm not using the string library and I KNOW there is a more
succinct method - but that darn syntax gets me every time.

Any help would be much appreciated!!


So, the fist character should be capitalized, that's easy right? Find
the first character, then capitalize it. (look up the function "toupper"
in the #include <cctype>. )

Then find the next period, from there find the next character and
capitalize it.

Keep going until you hit the end of the string.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 28 '06 #3
posted:
Hi there, everyone! I'm a student studying computer animation. But
alas, in order to graduate I have to take a programming class and it's
kicking my butt. I have two projects left to write (and believe me, to
some of the veterans out there, it'll be a piece of cake) one of which
takes a character array and capitalizes where necessary - eg. begining
of the string, after a period. Names and such aren't taken into
account. Like I said, very beginner level stuff. Still, I am having
trouble with the program flow.

I have a character array set up with a maximum input, and I wrote if
statements for every letter, but only for the first member of the
array.

Using a for loop, how do I generalize whether or not subsequent letters
need to be capitalized. I tried creating a bool variable to tell me
whether or not the letter in question IS a capital, but that's where I
get stuck. I'm not using the string library and I KNOW there is a more
succinct method - but that darn syntax gets me every time.

Any help would be much appreciated!!

~junk

/* fu********@gmail.com */

I'll get you started:
void ManipulateStringCharacterByCharacter(char* p_char)
{
bool capitalize_next_character = false;

for( ; *p_char; ++p_char)
{
char &current_char = *p_char;

if ( current_char == '.' )
{
capitalize_next_character = true;
continue;
}

//Here's your playground
}
}
-Tomás

Feb 28 '06 #4
In article <mq******************@news.indigo.ie>,
"Tomás" <NU**@NULL.NULL> wrote:
I'll get you started:
void ManipulateStringCharacterByCharacter(char* p_char)
{
bool capitalize_next_character = false;

for( ; *p_char; ++p_char)
{
char &current_char = *p_char;

if ( current_char == '.' )
{
capitalize_next_character = true;
continue;
}

//Here's your playground
}
}


Now I wouldn't do anything like that. I would do something more like:

char* find_letter( char* s ) {
while ( *s && ! isalpha( *s ) ) ++s;
return s;
}

char* find_period( char* s ) {
while ( *s && *s != '.' ) ++s;
return s;
}

Then...

char* p_char = str;
*p_char = toupper( *p_char );
while ( *p_char ) {
p_char = find_period( p_char );
p_char = find_letter( p_char );
if ( *p_char )
*p_char = toupper( *p_char );
}

In the process, I would show the student how to test each function
individually and when they were later introduced to std::string's find
functions, the functions would look natural.

Of course if I was the teacher, the student would learn about
std::string first thing.

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 28 '06 #5
On 2006-02-28, Daniel T. <po********@earthlink.net> wrote:
In article <mq******************@news.indigo.ie>,
"Tomás" <NU**@NULL.NULL> wrote:
I'll get you started:
void ManipulateStringCharacterByCharacter(char* p_char)
{
bool capitalize_next_character = false;

for( ; *p_char; ++p_char)
{
char &current_char = *p_char;

if ( current_char == '.' )
{
capitalize_next_character = true;
continue;
}

//Here's your playground
}
}


Now I wouldn't do anything like that. I would do something more like:

char* find_letter( char* s ) {
while ( *s && ! isalpha( *s ) ) ++s;
return s;
}

char* find_period( char* s ) {
while ( *s && *s != '.' ) ++s;
return s;
}

Then...

char* p_char = str;
*p_char = toupper( *p_char );
while ( *p_char ) {
p_char = find_period( p_char );
p_char = find_letter( p_char );
if ( *p_char )
*p_char = toupper( *p_char );
}

In the process, I would show the student how to test each function
individually and when they were later introduced to std::string's find
functions, the functions would look natural.

Of course if I was the teacher, the student would learn about
std::string first thing.


It's a plain evil assignment. Its a hard problem to programmatically
capitalize arbitrary text. You need a natural language parser,
combined with an enormous dictionary of arbitrary rules. I once wrote
a program to fix the capitalization of names, which were all
uppercase, since they looked bad in a mail merge. Anybody got a manual
for how names ought to be capitalized? And that's just a sub-problem
of this assignment.

How should the following sentence be capitalized?

ed mcbain wandered around the o.p.e.c. meeting, and purchased several
copies of "the flying squirrel who ate the soup," which he passed to
to the ncos guarding his manhattan apartment.

--
Neil Cerutti
A song fest was hell at the Methodist church Wednesday. --Church
Bulletin Blooper
Mar 1 '06 #6
In article <sl**********************@FIAD06.norwich.edu>,
Neil Cerutti <le*******@email.com> wrote:
On 2006-02-28, Daniel T. <po********@earthlink.net> wrote:
In article <mq******************@news.indigo.ie>,
"Tomás" <NU**@NULL.NULL> wrote:
I'll get you started:
void ManipulateStringCharacterByCharacter(char* p_char)
{
bool capitalize_next_character = false;

for( ; *p_char; ++p_char)
{
char &current_char = *p_char;

if ( current_char == '.' )
{
capitalize_next_character = true;
continue;
}

//Here's your playground
}
}


Now I wouldn't do anything like that. I would do something more like:

char* find_letter( char* s ) {
while ( *s && ! isalpha( *s ) ) ++s;
return s;
}

char* find_period( char* s ) {
while ( *s && *s != '.' ) ++s;
return s;
}

Then...

char* p_char = str;
*p_char = toupper( *p_char );
while ( *p_char ) {
p_char = find_period( p_char );
p_char = find_letter( p_char );
if ( *p_char )
*p_char = toupper( *p_char );
}

In the process, I would show the student how to test each function
individually and when they were later introduced to std::string's find
functions, the functions would look natural.

Of course if I was the teacher, the student would learn about
std::string first thing.


It's a plain evil assignment. Its a hard problem to programmatically
capitalize arbitrary text.


Well, the assignment was to capitalize the first letter in the string,
and each letter immediately after a period. Which is a bit different,
and quite a bit simpler than properly capitalizing arbitrary text.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Mar 2 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: dam_fool_2003 | last post by:
Friends, cannot we malloc a array? So, I tried the following code: int main(void) { unsigned int y={1,3,6},i,j; for(i=0;i<3;i++) printf("before =%d\n",y); *y = 7; /* 1*/
15
by: ehabaziz2001 | last post by:
Hi, Till now I do not understand how the null character automatically added to the end of the string and it is not an element of the string array . All books said the null character (\0) added...
7
by: arnuld | last post by:
i am trying to implement C style strings in C++ (from chapter 4 "C++ Primer 4/e"): // reading from std::cin for a c-string // (a null terminated character array) #include <iostream> #include...
44
by: Kulgan | last post by:
Hi I am struggling to find definitive information on how IE 5.5, 6 and 7 handle character input (I am happy with the display of text). I have two main questions: 1. Does IE automaticall...
14
by: Shhnwz.a | last post by:
Hi, I am in confusion regarding jargons. When it is technically correct to say.. String or Character Array.in c. just give me your perspectives in this issue. Thanx in Advance.
15
by: CptDondo | last post by:
I came across this bit of code: char devname = "wl0"; .... devname++; This looks wrong to me.... I am chasing a bad pointer issue in this code, and I suspect this is not valid C. --Yan
6
by: borophyll | last post by:
Hi Please let me know if I have this clear. The basic source character set is the list of (96) characters that all implementations must have in their vocabulary. All other characters...
13
by: Ivan | last post by:
Hi, What is the best syntax to use a char to index into an array. /////////////////////////////////// For example int data; data = 1;
152
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.