|
-
February 18th, 2009, 05:35 AM
#14
Re: String problems
 Originally Posted by chibicitiberiu
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?
You assumed that you did know how much memory by doing this:
Code:
for (i=lastslash;i<=strlen(pat);i++)
filename[i-lastslash]=pat[i];
So how big were you expecting the filename string to be in the code above? Whatever that is, you need to create or have access to a buffer of that size first before this code is invoked.
Once you know that, then you use new[] and delete[] to allocate and deallocate memory. But as JohnW pointed out, it would be much worth your while to write a string class and use that instead. But that requires you know how to use dynamic allocation (new[]/delete[]).
Regards,
Paul McKenzie
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
|