Results 1 to 4 of 4
Dear Friends,
I have a text file from which i read a number of names with their lengths at the run-time. Now i want to created a char array having ...
- 04-04-2010 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 9
Array Creation at run-time in c++/Linux
Dear Friends,
I have a text file from which i read a number of names with their lengths at the run-time. Now i want to created a char array having the length and name as already read from the text file at the run-time. There is no compilation involved. Every thing is happening at the run-time. I tried using STL like map along with malloc but i am unable to name an array at run-time. I can keep some type of mapping with previously created arrays , but that would be very inefficient implementation.
Please help.
Regards,
Raghuvendra Kumar
- 04-04-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
So, you want to have a named variable using the name you got at runtime? Sorry, but not possible. As you surmised, you can use some sort of map to hold and lookup that information. As for inefficient, generally it isn't inefficient to use a map, or hashmap to look up names since it uses a binary or hash search which are very efficient in searching large data sets.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 04-08-2010 #3Just Joined!
- Join Date
- Apr 2010
- Posts
- 5
I think you can also try to use double pointer?
like
char **names;
read your number of arrays want to initialize
names = malloc(sizeof(char*) * number_of_arrays);
and then individually malloc each array.
- 04-08-2010 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote
