The trouble is that my programme is printing out a load of rubbish when I try and print out the Linked List.
Its printing out a load of characters such as dollar signs and maths symbols. I figure this is because I'm printing out the element out in the wrong format. Can anyone give me a hand figureing out where I am going wrong please?
Code:#include <stdio.h> #include <stdlib.h> typedef struct N { char x[1]; struct N *next; } List; List *insertlist(char word[1], List * b) { List *c = calloc(1, sizeof(List)); strcpy( c->x, word ); c->next = b; return c; } int main(int argc, char *argv[]) { FILE *fp; List *z = NULL; int c = 0; char x; char word[1]; fp = fopen(argv[1], "r"); while ( (x = fgetc(fp)) != EOF) { printf("%c", x); if(c==0) { if(x == ';') { c = 1; z = insertlist(word, z); } else { z = insertlist(word, z); } } else if(c==1) { if(x == 10) { c = 0; } } } fclose(fp); while(z->next != NULL) { printf("%c", z); z = z->next; } }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.