Finding no. of elements in ptr array
I have an array of CString*:
CString* FilesFromAsc=(function that returns CString*)
I now want to loop through all the elements of FilesFromAsc. So I figure this will work:
while(FilesFromAsc[x]!="")
{
(do whatever)
x++
}
however when FilesFromAsc[x] does not exist i get an unhandled exception error.The same happens if i use:
while(FilesFromAsc[x])
instead.
I think I know why i get the error (because the variable it is trying to check doesn''t exist) but I dont know how to loop through the elements until it reaches the end.
Any help on this is much appreciated
Thanks
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Can you give us more information on the function that returns CString*, because if it returns the address of a local variable, this variable is destructed and the pointer has the address of another variable...
I don''t think there is any "legal" way of finding how many elements there is in an array when all you have is a pointer.
You should modify the function that returns a CString* so that it can also return the number of elements.
Example :
CString* TheFunction( int& nNumberOfElements );
(it could also simply return NULL if ''nNumberOfElements'' is 0)
Personal comment :
you should try STL and use the a container (eg : list) to return a list of string
Have fun
Blaster
BlasterSoft : http://www.blastersoft.com
Strategy First : http://www.strategyfirst.com
You should modify the function that returns a CString* so that it can also return the number of elements.
Example :
CString* TheFunction( int& nNumberOfElements );
(it could also simply return NULL if ''nNumberOfElements'' is 0)
Personal comment :
you should try STL and use the a container (eg : list) to return a list of string
Have fun
Blaster
BlasterSoft : http://www.blastersoft.com
Strategy First : http://www.strategyfirst.com
Thanks guys I found a way to do it similar to Blaster's idea. It returns NULL if it has no elements and if it does then I make the last element="NULL" and then loop until the current element is NULL.
However HiddenInBSP has worried me. The function that returns the CString* is this:
Is this a bad way of doing this? Because if it is im in trouble cos I've done it all over the place.
Thanks for your help
Edited by - Zeke on June 5, 2001 10:52:31 AM
However HiddenInBSP has worried me. The function that returns the CString* is this:
|
Is this a bad way of doing this? Because if it is im in trouble cos I've done it all over the place.
Thanks for your help
Edited by - Zeke on June 5, 2001 10:52:31 AM
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement