File Format:
7 49
73 58
130 72
144 78
123 9
40 65
92 42
187 3
127 29
I have to read these numbers (has 50 such lines) in the way Xvalue .... Yvalue in the linked list. I am having trouble reading the numbers. I have created the linked list as follows:
list L;
node *p, *q;
int i;
L = (list *)malloc(sizeof(node));
L -> x = L -> y = 0;
L -> nextx = L -> nexty = NULL;
FILE *fp;
fp = fopen("points.txt", "r");
if (fp == NULL)
{
fprintf(stderr, "Error: unable to open file...\n");
}
p = L;
for (i=0; i<100; ++i)
{
q = (node *)malloc(sizeof(node));
q -> x = // store x values here
q -> y = // store y values here
q -> nextx = q -> nexty = NULL;
p -> nextx = p -> nexty = q;
p = q;
}
fscanf(fp, "%d%d", &(q -> x), &(q -> y));?L = (list *)malloc(sizeof(node));Assigninglist*to a variable having typelistlooks weird. Also why the size to allocate is one ofnodewhile the buffer seems to be used aslist? By the way, what arelistandnode?if (fscanf(fp, "%d%d", &(q -> x), &(q -> y)) != 2) { free(q); break; }.Error: unable to open file.... This will be dangerous.Listandnode. The handling ofList Lseems wrong and having bothnextxandnextyseems wrong. Normally a linked list only has one "next"-pointer.