Look, you do almost the exact same thing twice:
Code:
scanf("%d%d", &x, &y);
diff = y-x;
Push(&head, diff);
tail = head;
while(getchar()!='\n');
while(fgets(str, BUFSIZE, stdin) != NULL) {
sscanf(str, "%d%d", &x, &y);
diff = y-x;
Push(&(tail->next), diff);
tail = tail->next;
}
The whole point of having functions is that you don't have to duplicate code. There are endless reasons to NOT DUPLICATE CODE FOR NO REASON, and absolute none for doing it.
Thus, you write a function to get two number and return diff. This is the example at the end of the page I posted:
Code:
int getNumber (int *num) {
char buffer[1024];
fgets(buffer,1024,stdin);
return sscanf(buffer, "%d", num);
}
Do you see how incredibly simple it would be to modify that to return that "diff" value? That's what functions are for!