|
-
February 18th, 2009, 05:12 AM
#13
Re: String problems
 Originally Posted by Paul McKenzie
Second, char* is not a string. You need to allocate memory and point the pointer to the beginning of this buffer. This simulates string handling, since there is no real "strings" in your version of C++ (which is very old). That's why this code is no good:
Code:
char* filename;
if (lastslash!=0) lastslash++;
for (i=lastslash;i<=strlen(pat);i++)
filename[i-lastslash]=pat[i];
What buffer is "filename" pointing to? It's pointing to a random section of memory. You then attempt to write to this random memory, and who knows what will happen.
Regards,
Paul McKenzie
Than how do I do that? I don't really know how to allocate memory, i know very few information about pointers.
How do I know how much memory will this string need?
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
|