By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

strupr Postmortem Analysis

P: n/a
I found a string to upper function that looks like this:

char *strupr(char *string)
{
char *s;
if (string)
{
for (s = string; *s; ++s)
*s = toupper(*s);
}
return string;
}

It works and all is ok, but I thought I could trim it down to the
following that doesn't work:

char *strupr(char *string)
{
// char *s;
if (string)
{
// for (s = string; *s; ++s)
for (string; *string; ++string)
// *s = toupper(*s);
*string = toupper(*string);
}
return string;
}

Can someone explain why the bottom function doesn't work? Thanks!

Jul 5 '06 #1
Share this Question
Share on Google+
23 Replies


P: n/a
<hu************@yahoo.comwrote:
I found a string to upper function that looks like this:

char *strupr(char *string)
{
char *s;
if (string)
{
for (s = string; *s; ++s)
*s = toupper(*s);
}
return string;
}

It works and all is ok, but I thought I could trim it down to the
following that doesn't work:

char *strupr(char *string)
{
// char *s;
if (string)
{
// for (s = string; *s; ++s)
for (string; *string; ++string)
// *s = toupper(*s);
*string = toupper(*string);
}
return string;
}

Can someone explain why the bottom function doesn't work? Thanks!
Yes. The original function kept a copy of the beginning of the string
('string'), and returned it. In the second function, you are returning
the modified pointer, which now points to the terminating NUL character.

--
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation
Jul 5 '06 #2

P: n/a
I found a string to upper function that looks like this:
>
char *strupr(char *string)
{
char *s;
if (string)
{
for (s = string; *s; ++s)
*s = toupper(*s);
}
return string;
}

It works and all is ok, but I thought I could trim it down to the
following that doesn't work:
line 1char *strupr(char *string)
line 2{
line 3// char *s;
line 4 if (string)
line 5 {
line 6// for (s = string; *s; ++s)
line 7 for (string; *string; ++string)
line 8// *s = toupper(*s);
line 9 *string = toupper(*string);
line 10 }
line 11 return string;
line 12}
>
Can someone explain why the bottom function doesn't work? Thanks!
I see part of the problem: line 9, "*string = toupper(*string);". I'm
stepping over the contents of the pointer "string", yes? As the
modified code is written, every instance through the for loop, *string
is given some new value which then breaks, yes?

If someone could step me through the loop that might clear things up
for me. I'm new to pointers... Thanks.

Jul 5 '06 #3

P: n/a
hu************@yahoo.com wrote:
I found a string to upper function that looks like this:

char *strupr(char *string)
Identifiers beginning with "str" followed by a lowercase letter are
reserved for future string functions.
{
char *s;
if (string)
{
for (s = string; *s; ++s)
*s = toupper(*s);
That should really be "*s = toupper((unsigned char)*s);", char can be
signed and passing a value that does not fit into an unsigned char and
is not EOF is undefined.
}
return string;
}

It works and all is ok, but I thought I could trim it down to the
following that doesn't work:

char *strupr(char *string)
{
// char *s;
if (string)
{
// for (s = string; *s; ++s)
for (string; *string; ++string)
// *s = toupper(*s);
*string = toupper(*string);
}
return string;
}

Can someone explain why the bottom function doesn't work? Thanks!
What do you mean by "doesn't work"? What did it do differently than
what you expected? Where is the actual code that you are using that
demonstrates the problem?

The second function is not functionally identical to the first one; the
first function returns a pointer to the beginning of the string
provided, the second function returns a pointer to the end of the
string. If you are doing something like this:

char s[] = "test";
printf("%s\n", strupr(s));

the result probably won't be what you expect whereas this:

char s[] = "test";
strupr(s);
printf("%s\n", s);

will work as expected.

It should be noted that since the function operates on the string
provided that something like this would result in undefined behavior:

strupr("test");

The first function can be reduced to something like this:

char *strupr(char *string)
{
char *s = string;
if (s)
for (s; *s; ++s)
*s = toupper(*s);
return string;
}

(Some people would object to the lack of brackets, add them as you see
fit.)

or even:

char *strupr(char *string)
{
char *s = string;
if (s)
do { *s = toupper(*s); } while (*s++);
return string;
}

Robert Gamble

Jul 5 '06 #4

P: n/a
Robert Gamble wrote:
hu************@yahoo.com wrote:
>>I found a string to upper function that looks like this:

char *strupr(char *string)


Identifiers beginning with "str" followed by a lowercase letter are
reserved for future string functions.

>>{
char *s;
if (string)
{
for (s = string; *s; ++s)
*s = toupper(*s);


That should really be "*s = toupper((unsigned char)*s);", char can be
signed and passing a value that does not fit into an unsigned char and
is not EOF is undefined.
Is it? I thought toupper and tolower return their argument unchanged if
its value is invalid.

--
Ian Collins.
Jul 5 '06 #5

P: n/a
posted:
I found a string to upper function that looks like this:

The following is far simpler:
#include <ctype.h>

void StringUp( char *p )
{
while( *p = toupper(*p) ) ++p;
}

--

Frederick Gotham
Jul 5 '06 #6

P: n/a
Ian Collins wrote:
Robert Gamble wrote:
hu************@yahoo.com wrote:
>I found a string to upper function that looks like this:

char *strupr(char *string)

Identifiers beginning with "str" followed by a lowercase letter are
reserved for future string functions.

>{
char *s;
if (string)
{
for (s = string; *s; ++s)
*s = toupper(*s);

That should really be "*s = toupper((unsigned char)*s);", char can be
signed and passing a value that does not fit into an unsigned char and
is not EOF is undefined.
Is it? I thought toupper and tolower return their argument unchanged if
its value is invalid.
7.4p1 (ctype.h):
"The header <ctype.hdeclares several functions useful for classifying
and mapping
characters. In all cases the argument is an int, the value of which
shall be
representable as an unsigned char or shall equal the value of the macro
EOF. If the
argument has any other value, the behavior is undefined."

7.4.2.1p3 (tolower):
If the argument is a character for which isupper is true and there are
one or more
corresponding characters, as specified by the current locale, for which
islower is true,
the tolower function returns one of the corresponding characters
(always the same one
for any giv en locale); otherwise, the argument is returned unchanged.

Robert Gamble

Jul 5 '06 #7

P: n/a
Frederick Gotham wrote:
posted:
I found a string to upper function that looks like this:


The following is far simpler:
#include <ctype.h>

void StringUp( char *p )
{
while( *p = toupper(*p) ) ++p;
while(*p = toupper((unsigned char)*p) ) ++p;
}
Simpler, yes, but it doesn't do the same thing as the function the OP
presented, namely returning a pointer to the beginning of the string
provided.

Robert Gamble

Jul 5 '06 #8

P: n/a
Robert Gamble wrote:
Ian Collins wrote:
>>Robert Gamble wrote:
>>>That should really be "*s = toupper((unsigned char)*s);", char can be
signed and passing a value that does not fit into an unsigned char and
is not EOF is undefined.

Is it? I thought toupper and tolower return their argument unchanged if
its value is invalid.


7.4p1 (ctype.h):
"The header <ctype.hdeclares several functions useful for classifying
and mapping
characters. In all cases the argument is an int, the value of which
shall be
representable as an unsigned char or shall equal the value of the macro
EOF. If the
argument has any other value, the behavior is undefined."

7.4.2.1p3 (tolower):
If the argument is a character for which isupper is true and there are
one or more
corresponding characters, as specified by the current locale, for which
islower is true,
the tolower function returns one of the corresponding characters
(always the same one
for any giv en locale); otherwise, the argument is returned unchanged.
Can't argue with that.

--
Ian Collins.
Jul 5 '06 #9

P: n/a
Robert Gamble posted:

while(*p = toupper((unsigned char)*p) ) ++p;

This would imply that the integer at address "p" might be negative.

If the integer is negative, then do we not have a error? Forcing the
negative number to be positive won't solve the problem.

If anything, would the following not be better:

#include <assert.h>
#include <ctype.h>

void StringUp( char *p )
{
do assert( *p >= 0 );
while( *p = toupper( *p ), *p++ );
}

#include <stdio.h>

int main(void)
{
char array[] = "The man walked by the 3rd door and turned right.";

StringUp(array);

puts(array);
}
--

Frederick Gotham
Jul 5 '06 #10

P: n/a
>Robert Gamble posted:
>while(*p = toupper((unsigned char)*p) ) ++p;
In article <Y5*******************@news.indigo.ie>
Frederick Gotham <fg*******@SPAM.comwrote:
>This would imply that the integer at address "p" might be negative.
As indeed it might.
>If the integer is negative, then do we not have a error?
Maybe, but probably not:

/* signed */ char buf[] = "sláinte";
/* signed */ char *p = buf;

while ((*p = toupper((unsigned char)*p)) != '\0')
p++;
puts(buf);

Without the "unsigned", on my systems where plain "char" is signed,
the word is mangled; with it, on those same systems, it works right
(producing SLÁINTE).
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Jul 5 '06 #11

P: n/a
Frederick Gotham wrote:
Robert Gamble posted:

while(*p = toupper((unsigned char)*p) ) ++p;


This would imply that the integer at address "p" might be negative.
Right, since char may be signed it is certainly possible for the values
of an array of char to be negative.
If the integer is negative, then do we not have a error?
What would be erroneous about it?
Forcing the
negative number to be positive won't solve the problem.
There isn't a problem except the fact that you can't pass a negative
value (except EOF) to the toupper function and casting the value to
unsigned char certainly does address that.
If anything, would the following not be better:

#include <assert.h>
#include <ctype.h>

void StringUp( char *p )
{
do assert( *p >= 0 );
Why do you think this *p can't be negative?
while( *p = toupper( *p ), *p++ );
Yuck, 0 points for style.
}

#include <stdio.h>

int main(void)
{
char array[] = "The man walked by the 3rd door and turned right.";

StringUp(array);

puts(array);
}
It is possible for char to be signed. It is also possible for, in some
locale, there to be letters that have negative values. The only way to
perform portable case conversions on these characters would be to use
the toupper/tolower functions and the only way to do that without
invoking undefined behavior is to cast them to unsigned char. The
implementation will be expecting to receive such characters so casted.
I don't understand where you think the problem lies here.

Robert Gamble

Jul 5 '06 #12

P: n/a
I found a string to upper function that looks like this:

char *strupr(char *string)

Identifiers beginning with "str" followed by a lowercase letter are
reserved for future string functions.
{
char *s;
if (string)
{
for (s = string; *s; ++s)
*s = toupper(*s);

That should really be "*s = toupper((unsigned char)*s);", char can be
signed and passing a value that does not fit into an unsigned char and
is not EOF is undefined.
}
return string;
}

It works and all is ok, but I thought I could trim it down to the
following that doesn't work:

char *strupr(char *string)
{
// char *s;
if (string)
{
// for (s = string; *s; ++s)
for (string; *string; ++string)
// *s = toupper(*s);
*string = toupper(*string);
}
return string;
}

Can someone explain why the bottom function doesn't work? Thanks!

What do you mean by "doesn't work"? What did it do differently than
what you expected? Where is the actual code that you are using that
demonstrates the problem?
Good point :) . It did work, but sent "nothing" back to the screen... I
was expecting to see the capitalized version of the text that was sent
in.
The second function is not functionally identical to the first one; the
first function returns a pointer to the beginning of the string
provided, the second function returns a pointer to the end of the
string. If you are doing something like this:

char s[] = "test";
printf("%s\n", strupr(s));

the result probably won't be what you expect whereas this:

char s[] = "test";
strupr(s);
printf("%s\n", s);

will work as expected.

It should be noted that since the function operates on the string
provided that something like this would result in undefined behavior:

strupr("test");

The first function can be reduced to something like this:

char *strupr(char *string)
{
char *s = string;
if (s)
for (s; *s; ++s)
*s = toupper(*s);
return string;
}

(Some people would object to the lack of brackets, add them as you see
fit.)

or even:

char *strupr(char *string)
{
char *s = string;
if (s)
do { *s = toupper(*s); } while (*s++);
return string;
}

Robert Gamble
Most cool. Thanks for the help!

Jul 5 '06 #13

P: n/a
I found a string to upper function that looks like this:
>

The following is far simpler:
#include <ctype.h>

void StringUp( char *p )
{
while( *p = toupper(*p) ) ++p;
}

--

Frederick Gotham
I changed your code to this and got "null" back...

1 #include <ctype.h>
2 #include <stdio.h>
3
4 //void StringUp( char *p )
5 char StringUp( char *p )
6 {
7 while( *p = toupper(*p) ) ++p;
8 return *p;
9 }
10
11 int main()
12 {
13 char str[20] = {"this is a test"};
14 printf("--%s\n",StringUp(str));
15 return 0;
16 }

Is there anyway to salvage what I did to get the all caps string
returned from the function?

Jul 5 '06 #14

P: n/a
while(*p = toupper((unsigned char)*p) ) ++p;
>

This would imply that the integer at address "p" might be negative.

If the integer is negative, then do we not have a error? Forcing the
negative number to be positive won't solve the problem.

If anything, would the following not be better:

#include <assert.h>
#include <ctype.h>

void StringUp( char *p )
{
do assert( *p >= 0 );
while( *p = toupper( *p ), *p++ );
}

#include <stdio.h>

int main(void)
{
char array[] = "The man walked by the 3rd door and turned right.";

StringUp(array);

puts(array);
}
--

Frederick Gotham
That looks interesting. I tried to convert your code to a function that
would return a value and came up with this that seg faults:

1 #include <assert.h>
2 #include <stdio.h>
3
4 char StringUp( char *p )
5 {
6 do assert( *p >= 0 );
7 while( *p = toupper( *p ), *p++ );
8 return *p;
9 }
10
11 int main(void)
12 {
13 char array[] = "The man walked by the 3rd door and turned
right.";
14 printf("--%s\n",StringUp(array));
15 }

I would think that line 8 should be "return p", but I get:
test.c:8: warning: return makes integer from pointer without a cast

Once I get the code right to return a value I want to stick some
printf's in the function to trace what's going on. Right now I'm not
100%... Thanks!

Jul 5 '06 #15

P: n/a
hu************@yahoo.com said:

<snip>
>
That looks interesting. I tried to convert your code to a function that
would return a value and came up with this that seg faults:

1 #include <assert.h>
2 #include <stdio.h>
3
4 char StringUp( char *p )
You have defined StringUp to return a single char...

<snip>
10
11 int main(void)
12 {
13 char array[] = "The man walked by the 3rd door and turned
right.";
14 printf("--%s\n",StringUp(array));
....but here you treat it as if it returned a string.
15 }

I would think that line 8 should be "return p", but I get:
test.c:8: warning: return makes integer from pointer without a cast
If you make it "return p;" you'll be returning a pointer to the null
character that terminates the string, which may or may not be what you want
but printf won't display very much.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 5 '06 #16

P: n/a
hu************@yahoo.com wrote:
I changed your code to this and got "null" back...

1 #include <ctype.h>
2 #include <stdio.h>
3
4 //void StringUp( char *p )
5 char StringUp( char *p )
If you want to return a string and not a single character, you should use
char *, so char *StringUp( char *p ) is what you propably wanted.
6 {
7 while( *p = toupper(*p) ) ++p;
This loop is executed until *p == 0 (the end of the string is reached)
8 return *p;
so *p == 0 at this point, and you are always returning 0 (not the character
'0', but 0, the character '\0').
9 }
10
11 int main()
12 {
13 char str[20] = {"this is a test"};
14 printf("--%s\n",StringUp(str));
15 return 0;
16 }

Is there anyway to salvage what I did to get the all caps string
returned from the function?
Yes, again you must somehow get the pointer to the first character and
return this pointer.
Like so:
char *StringUp( char *p )
{
char *string_start = p;
while( *p = toupper(*p) ) ++p;
return string_start;
}

--
Roland Csaszar ----------- \\\ /// -------------- +43 316 495 2129
Software Development ------ \\\ /// ----------- http://www.knapp.com
KNAPP Logistics Automation - \\V// - mailto:ro************@knapp.com
Jul 5 '06 #17

P: n/a
hu************@yahoo.com wrote:
1 #include <assert.h>
2 #include <stdio.h>
3
4 char StringUp( char *p )
----------^^^^^

Should be char *StringUp( char *p )
5 {
6 do assert( *p >= 0 );
7 while( *p = toupper( *p ), *p++ );
8 return *p;
You are returning the 0 ('\0') which is positioned after the last character
of the string.
9 }
10
11 int main(void)
12 {
13 char array[] = "The man walked by the 3rd door and turned
right.";
14 printf("--%s\n",StringUp(array));
15 }

I would think that line 8 should be "return p", but I get:
Yes, it should be return p (well, not really, but you should return a
pointer to a char, not a char)
test.c:8: warning: return makes integer from pointer without a cast
And this errormessage tells you, that the type of the return value is wrong.
You are telling the compiler that you are returning a char (an integer) in
the function's definition, but return a pointer to a char (a pointer to an
integer).

--
Roland Csaszar ----------- \\\ /// -------------- +43 316 495 2129
Software Development ------ \\\ /// ----------- http://www.knapp.com
KNAPP Logistics Automation - \\V// - mailto:ro************@knapp.com
Jul 5 '06 #18

P: n/a
I changed your code to this and got "null" back...

1 #include <ctype.h>
2 #include <stdio.h>
3
4 //void StringUp( char *p )
5 char StringUp( char *p )

If you want to return a string and not a single character, you should use
char *, so char *StringUp( char *p ) is what you propably wanted.
Ahhh, I see the reasoning now...
6 {
7 while( *p = toupper(*p) ) ++p;

This loop is executed until *p == 0 (the end of the string is reached)
I didn't understand that contents of the "while" condition would be
executed when the condition is true. That's pretty fancy stuff.
8 return *p;

so *p == 0 at this point, and you are always returning 0 (not the character
'0', but 0, the character '\0').
Would you not be returning a pointer to "cell zero" of the pointer "p"?
To me, that seems like what is going on, so that when line 14 prints
the string, the string starts at "cell zero" and continues printing
each "cell" until, but not including, the null character "\0". No?
9 }
10
11 int main()
12 {
13 char str[20] = {"this is a test"};
14 printf("--%s\n",StringUp(str));
15 return 0;
16 }

Is there anyway to salvage what I did to get the all caps string
returned from the function?

Yes, again you must somehow get the pointer to the first character and
return this pointer.
Like so:
char *StringUp( char *p )
{
char *string_start = p;
while( *p = toupper(*p) ) ++p;
return string_start;
}
Wow. That's good stuff! C is becoming fun learn. Thanks a lot for
clearing that up!

Jul 5 '06 #19

P: n/a
<snip>

That looks interesting. I tried to convert your code to a function that
would return a value and came up with this that seg faults:

1 #include <assert.h>
2 #include <stdio.h>
3
4 char StringUp( char *p )

You have defined StringUp to return a single char...

<snip>
10
11 int main(void)
12 {
13 char array[] = "The man walked by the 3rd door and turned
right.";
14 printf("--%s\n",StringUp(array));

...but here you treat it as if it returned a string.
15 }

I would think that line 8 should be "return p", but I get:
test.c:8: warning: return makes integer from pointer without a cast

If you make it "return p;" you'll be returning a pointer to the null
character that terminates the string, which may or may not be what you want
but printf won't display very much.
1 #include <assert.h>
2 #include <stdio.h>
3
4 char *StringUp(char *p)
5 {
6 char *string_start=p;
7 while(*p=toupper(*p))++p;
8 return string_start;
9 }
10
11 int main(void)
12 {
13 char array[]="The man walked by the 3rd door and turned
right.";
14 printf("--%s\n",StringUp(array));
15 }

Ok, let's now say the new code is in lines 1-15 above (thanks Roland!).

If in line 8 I have "return string_start;", I get my desired results.
Is what is being returned a pointer? I thought pointers had to be
prefaced with an "*". Yes?

Is there some way I can printf the memory addresses of the content of
*string_start?

Jul 5 '06 #20

P: n/a

hu************@yahoo.com wrote:
char *strupr(char *string)
{
// char *s;
if (string)
{
// for (s = string; *s; ++s)
for (string; *string; ++string)
// *s = toupper(*s);
*string = toupper(*string);
}
return string;
}
The revised version also does convert the string to upper case. The
converted string can be accessed through the parameter pointer while
the returned pointer is located at the end of that string.

lovecreatesbeauty

Jul 5 '06 #21

P: n/a
hu************@yahoo.com said:

<snip>
>
1 #include <assert.h>
You don't use this, so you could just remove it.

By the way, the line numbers are a nuisance, since they prevent us from
easily compiling your code to syntax-check it.
2 #include <stdio.h>
This line brings in various prototypes and stuff for standard I/O. It's fine
- no problem with it.

What you are missing, though, is a prototype for toupper. I recommend that
you do this as well:

#include <ctype.h>

This will give you the necessary prototype for toupper.
3
4 char *StringUp(char *p)
This line declares that StringUp is a function that takes a pointer to a
character and returns a pointer to a character. It's fine - no problem
here.
5 {
This line begins the definition of the function body.
6 char *string_start=p;
This line defines a pointer to char, and initialises it with the value
passed via the parameter p.
7 while(*p=toupper(*p))++p;
This line needs a slight modification. Your function has no guarantee that
the characters it is processing are representable as unsigned char, so it
would be wiser to write the line as follows:

while(*p=toupper((unsigned char)*p))++p;

It would be wiser still to separate the loop body line from the controlling
line, as this makes the code a little easier to read:

while(*p=toupper((unsigned char)*p))
++p;

And it would be fantastically wise to use a compound statement (although it
is not, strictly speaking, required):

while(*p=toupper((unsigned char)*p))
{
++p;
}

because, in the general case, it eases the process of modifying the loop to
incorporate any extra statements that you might require at some later
point.
8 return string_start;
This is fine - you're returning the value you passed originally, which you
carefully copied into string_start at the beginning of your function.
9 }
This line closes the function definition.
10
11 int main(void)
This line declares main to be a function taking no parameters and returning
an int. No problem here.
12 {
13 char array[]="The man walked by the 3rd door and turned
right.";
C doesn't support the wrapping of string literals around a newline
character. I realise that your code probably doesn't have this problem -
it's just something that happened in your news client. Still, it makes
compiling the code at this end a bit of a nuisance. If you have very long
string literals, you can fold them like this:

char array[]="The man walked by the 3rd"
" door and turned right.";

Note that there is no ,,,comma,,, in between the two lines.

The C preprocessor takes this absence of non-whitespace separators as a sign
that we're talking about just one string literal, so it glues the pieces
together for you - it's just as if you'd written:

char array[]="The man walked by the 3rd door and turned right.";
14 printf("--%s\n",StringUp(array));
15 }

Ok, let's now say the new code is in lines 1-15 above (thanks Roland!).

If in line 8 I have "return string_start;", I get my desired results.
Is what is being returned a pointer?
Yes.
I thought pointers had to be prefaced with an "*". Yes?
When you declare them, yes. In use, though, it depends on what you want.

In your case, you want the pointer value itself, not the thing pointed to.

return string_start;

means "return the value this pointer has", which is precisely what you need.

return *string_start; /* no! */

would mean "return the value of the character pointed to by string_start",
which is not what you want.
Is there some way I can printf the memory addresses of the content of
*string_start?
*string_start is a single character.

string_start is a single pointer value (colloquially, an address).

Which do you mean?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 5 '06 #22

P: n/a
On Wed, 05 Jul 2006 02:03:36 GMT, Frederick Gotham
<fg*******@SPAM.comwrote in comp.lang.c:
Robert Gamble posted:

while(*p = toupper((unsigned char)*p) ) ++p;


This would imply that the integer at address "p" might be negative.

If the integer is negative, then do we not have a error? Forcing the
negative number to be positive won't solve the problem.

If anything, would the following not be better:

#include <assert.h>
#include <ctype.h>

void StringUp( char *p )
{
do assert( *p >= 0 );
while( *p = toupper( *p ), *p++ );
^^^^

Are you aware that you don't need to dereference a pointer to
increment it?
}

#include <stdio.h>

int main(void)
{
char array[] = "The man walked by the 3rd door and turned right.";

StringUp(array);

puts(array);
}
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 5 '06 #23

P: n/a
Jack Klein posted:
> while( *p = toupper( *p ), *p++ );
^^^^

Are you aware that you don't need to dereference a pointer to
increment it?

Yes.

The pointer is dereferenced so that what it points to can be used as the
conditional expression for the while loop.
--

Frederick Gotham
Jul 5 '06 #24

This discussion thread is closed

Replies have been disabled for this discussion.