Abby wrote:
> From my code below, it will open a file specified in argv[1], then
> read line by line and store each line in an array call IPTemp.
> After reading until EOF, it will return array IPTemp to main, which
> you'll see a for loop here "for(i=0;i<6;i++)" ... I use 6 here,
> assuming there's 6 lines in the file I opened. How can I know exactly
> how many elements in my array? Please help...thanks a lot.
>
>
> #include <stdio.h>
>
> #define MAXLINES 200
> #define MAXLINELENGTH 30
>
Instead of fixing the maxlines and maxstringlength, you would
create a struct like
struct IP
{
char **ip;
unsigned total;
};
Then dynamically allocate the file lines into the struct. Member ip
is an array of strings of the ips and the member total represents the
total lines read and stored in the array. The max quantity of data
stored in the array would be moderated by the available memory.
--
Al Bowers
Tampa, Fl USA
mailto:
(remove the x)
http://www.geocities.com/abowers822/