data structure in c that will hold an unknown length of cstrings and have
the ability to remove them latter
In C what's the best data structure for storing an unknown amount of
values then removing many? I'm reading a file and each line is stored as a
c string in some larger data structure. Each line is probably less than 20
characters long and one example file has 300000 lines. Whatever
datastructure I'm going to use will only grow in size at it's initial
creation; from there it will only shrink in size. What would I use? In
Java I would use ArrayList or maybe Vector. Could a dynamic array work and
if yes how would it look like?
char aLine[21];
char *data = malloc(aLine);
fp = fopen("datafile", "r");
if(fp== NULL)
exit(EXIT_FAILURE);
while(fscanf(fp, "%20s", aLine) == 1)
{
data = aLine;
realloc(data, sizeof(data)+sizeof(aLine));
}
I've only seen
No comments:
Post a Comment