i'm trying to build a linked list from an input txt file.
example input file (note: the actual file has more parameters):
NAME: John
NUMBER: 3
NAME: Fred
NUMBER: 4
etc...
i wrote a bunch of code, but i kept getting bus error. i edited the heck out of it and settled for trying to just get the name to read, and i still got a bus error.
any ideas?
Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct people_node{
char *first_name;
}people;
int main(int argc,char *argv[])
{
FILE *community;
people *current;
char line[100], *token;
community = fopen(argv[1], "r");
current = malloc(sizeof(people));
while(fgets(line,100,community)!=NULL){
token = strtok(line," ");
token = strtok(NULL,"\n");
strcpy(current->first_name, token);
}
printf("%s\n", current->first_name);
return 0;
}
the argc, argv thing is because i have another input file for other purposes...