Mail Archives: djgpp/2001/11/30/20:31:38
Here's a toughy:
Using conventional C-style code,
something I wish to be portable,
how would you load in data for a
two-dimensional string array...
dynamically allocated:
example:
1- - - - - - - - - - - - - - - - -
unsigned char **StringArray;
2- - - - - - - - - - - - - - - - -
if ( (StringArray = (char **)malloc(1024*sizeof(char*)))==NULL ) {
printf("Error allocating buffer.\n");
exit(-1);
}
3- - - - - - - - - - - - - - - - -
if (((char*)StringArray[i] = (char*)malloc(13))==NULL) {
printf("Have reached the limit for the StringArray!.\n");
break;
}
memset(StringArray[i], 0, 13);
strcpy(StringArray[i], data);
++i;
- - - - - - - - - - - - - - - - -
NOW, here's the really tricky part!
in #3 I am getting data currently from a file,
reading a line at a time, and feeding that into
the freshly allocated string_array[i],
HOW CAN I SIMPLY LOAD THE _entire_ FILE
INTO MEMORY in one swift operation ?
say, using fread() ???
the string array in memory has the actual format
of:
char *StringArray1[i] = {
"item1a", "item1b",
"item2a", "item2b",
etc. etc.
};
the sizes of each string is unique....
the size of the array may change the next time
the program runs,
any ideas?
THANKS!
email: radsmail AT juno DOT com
http://members.tripod.com/~RadSurfer/
- Raw text -