|
-
April 26th, 2007, 01:00 AM
#1
CStrings Question: What is the difference between char str[] and char* str
Hi;
I guess I'm a newbie with this question.
My question is about C strings.
I'm trying to figure out why the behavior of these 2 strings are different as it relates to toupper() function ?
char str1[] ="For the perfecting of the saints";
char* str2 ="For the perfecting of the saints";
//when I call ucase(str1) everything works perfectly.
ucase(str1);
//but when i call
ucase(str2)
//it crashes. Can you tell me what's the difference between char str1[] and char* str2?
Here's the ucase() function i'm calling below.
//convert to uppercase
void ucase(char* buffer)
{
int len = strlen(buffer);
for(int i = 0; i < len; i++)
{
buffer[i] = toupper(buffer[i]);
}
}
I can loop through both just fine using something like this
for(int i =0; i<36; i++){
printf("here %c\n", str1[i]);
}
but when it seems to me toupper breaks when you use it with char* x for some reason.
Thanks in Advance.
Stev
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|