#include #include #include struct node { char* data; struct node* next; }; struct node* head = NULL; struct node* current = NULL; // insert link at the first location // void insert(char* data) { //create a link // struct node *link = (struct node*) malloc(sizeof(struct node)); // struct node *link = new struct node; // link->key = key; // link->data = data; //point it to old first node // link->next = head; // point first to new first node // head = link; } // display the list // void printList() { struct node *ptr = head; printf("head] =>\n"); //start from the beginning long i = 0; while(ptr != NULL) { i++; printf("%d: [%s]\n", i, ptr->data); ptr = ptr->next; } printf("[null]\n"); } int main(int argc, char** argv) { int MAXLEN = 99999; char buf[MAXLEN]; FILE* fp = fopen(argv[1], "r"); while (fgets(buf, MAXLEN, fp) != (char*)NULL) { buf[strlen(buf) - 1] = (char)NULL; char* tmp = new char[strlen(buf + 1)]; strcpy(tmp, buf); insert(tmp); } fclose(fp); // print the list dummy // printList(); // exit gracefully // return 0; }