you have a couple options: (1) put each of the strings in an array of strings, or (2) keep a linked list of the lines that are read.
Here is an example of using the array.
#include <stdio.h>
int main() {
int linecount = 0;
char *array[255] = {0}; // hold 255 lines
char buf[255]; <<HOW MUCH SHOULD WE ALOCATE TE BUFFER?
FILE* fp = fopen("somefile.txt","r");
if( fp == NULL) {
printf("Can't open the file\n");
return 1;
} // read each line of the file
while( fgets(buf,sizeof(buf),1,fp) != NULL) {
// count the lines or do other stuff here
array[linecount] = malloc(strlen(buf)+1);
strcy(array[linecount],buf);
linecount++;
}
// close the file
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Offline 21,963 posts
since Aug 2005