I
Ian Todd
Hi,
I am trying to read in a list of data from a file. Each line has a string in
its first column. This is what i want to read. I could start by saying
char[1000][] to read in 1000 lines to the array( i think!!).
But I want to use malloc. Each string is at most 50 characters long, and
there may be zero to thousands of lines. How do I actually start the array?
I have seen char **array etc. At first I tried char *array[50] but I think
that gives 50 pointers to chars
.How do I use malloc to set space for the
array once I know how many lines there are? is it
array=malloc(lines*sizeof(char *)) ??
Finally, I want to print each of the strings using printf. How do I access
say the 30th line?
I have sucessfully done this a few times with doubles, ints etc, but now
with strings it seems a 'two dimesional' problem and I'm confused with the
pointer aspect of it.
Can anyone start me off on a simple solution?
Thanks
Ian
I am trying to read in a list of data from a file. Each line has a string in
its first column. This is what i want to read. I could start by saying
char[1000][] to read in 1000 lines to the array( i think!!).
But I want to use malloc. Each string is at most 50 characters long, and
there may be zero to thousands of lines. How do I actually start the array?
I have seen char **array etc. At first I tried char *array[50] but I think
that gives 50 pointers to chars
array once I know how many lines there are? is it
array=malloc(lines*sizeof(char *)) ??
Finally, I want to print each of the strings using printf. How do I access
say the 30th line?
I have sucessfully done this a few times with doubles, ints etc, but now
with strings it seems a 'two dimesional' problem and I'm confused with the
pointer aspect of it.
Can anyone start me off on a simple solution?
Thanks
Ian