This is my program to read a file & print the lines out,
since im not familiar with link list, i got a seg fault from this.
Anyone can help me out,thx?
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct Node {
char line[1000];
struct Node *next;
} NodeT;
int main(int argc, char **argv) {
char line [1000];
FILE *fp;
NodeT *s, *head;
head = s;
if(argv[1] != NULL){
if((fp = fopen(argv[1],"r")) != NULL) {
while (fgets(s->line, 1000, fp) != NULL) {
printf("%s" ,line);
s = s->next;
}
s->next = NULL;
}
}
free(s);
free(head);
head = NULL;
s = NULL;
return 0;
}