Write a program that reads a file and builds a linked list in c
Answers
Answered by
0
I'm very new to C-programming, and I'm having
some difficulties. I'm trying to read line from line
to a text file, and then add each line to a simple
linked list. I have tried a lot, but I haven't found a
solution. So far in my code I'm able to read from
the file, but I can't understand how to save the
text line for line and add it to the linked list.
This is what I have so far:
struct list {
char string;
struct list *next;
};
typedef struct list LIST;
int main( void ) {
FILE *fp;
char tmp[ 100 ];
LIST *current, *head;
char c;
int i = 0;
current = NULL;
head = NULL;
If anyone could give me some pointers on what I
need to do next to make it work, I would highly
appreciate it. I'm used to Java, and somehow my
brain can't understand how to do these things in
C.
some difficulties. I'm trying to read line from line
to a text file, and then add each line to a simple
linked list. I have tried a lot, but I haven't found a
solution. So far in my code I'm able to read from
the file, but I can't understand how to save the
text line for line and add it to the linked list.
This is what I have so far:
struct list {
char string;
struct list *next;
};
typedef struct list LIST;
int main( void ) {
FILE *fp;
char tmp[ 100 ];
LIST *current, *head;
char c;
int i = 0;
current = NULL;
head = NULL;
If anyone could give me some pointers on what I
need to do next to make it work, I would highly
appreciate it. I'm used to Java, and somehow my
brain can't understand how to do these things in
C.
Similar questions