Created
May 7, 2015 20:45
-
-
Save soltys/538da3696f1d61533bfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct node_tag{ | |
int x; | |
struct node_tag* next; | |
}node; | |
node* addNode(node* list, int x){ | |
list->next = (node*) malloc(sizeof(node)); | |
list->next->next = NULL; | |
list->x = x; | |
return list->next; | |
} | |
int existOnList(node* list, int value){ | |
node* n = list; | |
while(n->next!= NULL){ | |
if(n->x == value){ | |
return 1; | |
} | |
n = n->next; | |
} | |
return 0; | |
} | |
void printList(node* list, node* secList){ | |
node* n = list; | |
while(n->next!= NULL){ | |
if (!existOnList(secList,n->x)) | |
{ | |
printf("%d\n", n->x); | |
} | |
n = n->next; | |
} | |
} | |
node* createNumberList(FILE* f){ | |
node* list = (node*) malloc(sizeof(node)); | |
node* head = list; | |
int value = 0; | |
while (fscanf(f, "%d", &value) != EOF){ | |
list = addNode(list, value); | |
} | |
return head; | |
} | |
int main(void) { | |
FILE* aFile = fopen("a.txt", "r"); | |
FILE* bFile = fopen("b.txt", "r"); | |
node* alist = (node*) createNumberList(aFile); | |
node* blist = (node*) createNumberList(bFile); | |
printList(alist, blist); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment