|
-
November 1st, 2002, 08:46 PM
#1
HELP: What's the problem here?
I'm missing very basic regarding the char *. Why the program crashes when strcpy( result, Digits);
void Add(char * result)
{
char Digits[] = "1234567";
strcpy( result, Digits);
}
I'll appreciate your help.
Luis F Hernandez
EBS
-
November 1st, 2002, 08:54 PM
#2
how to you call the function Add()? Is "result" pointing to something? Is it pointing to something big enough to hold the string "1234567"
Like: Is "result" also a character array of at least 7 in length.
-
November 1st, 2002, 11:45 PM
#3
Actually....
The buffer needs to hold atleast 8 - 7 chars plus a null terminator, the '\0' char or 0.
-
November 3rd, 2002, 12:07 AM
#4
Explanation-Explicación
When you call the function "void Add(char *result)" you
must pass a pointer that realy points to some memory
allocated.
Example 1:
char memory[8];
Add(memory);
Example 2:
char *memory = new char[8];
Add(memory);
The size is greater than 7 because the string contains 7 digits and a null character that you don't see (7 + 1 = 8).
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
|