TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TCLUG:10354] c question
Create an array of pointers, read in each line, make a copy of the line and
place it's address in the array.
At the end, n is the number of lines stored:
#define MAX 100
char *array[MAX];
char line[100];
FILE *fp = fopen("myfile", "r");
int n=0;
while (n<MAX && fgets(line, sizeof(line), fp))
array[n++] = strdup(line);
Patrick McCabe
----- Original Message -----
From: bliss <bliss@treewax.com>
To: <tclug-list@mn-linux.org>
Sent: Monday, November 22, 1999 2:19 PM
Subject: [TCLUG:10354] c question
> i have a file server.list that contains server names
> server1
> server2
> and i need to initialize an array to those strings
> array[0] = "server1";
> array[1] = "server2";
> but i want to do this dynamicly, ie i want this program to read the file
and
> assign each string to the array subscript
> array[0] --> server1 while reading the file
> how do i get a line and assign a string to an array
> then move forward in the array and assign the next string to the next
space
> in the array?
>
> any ideas ???
>
> --chris engstrom
> bl155@treewax.com
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tclug-list-unsubscribe@mn-linux.org
> For additional commands, e-mail: tclug-list-help@mn-linux.org