#include #include FILE *inp1, *inp2, *oup; char str1[1024] = "", str2[1024] = ""; void strip() { char temp[1024] = "", temp2[1024] = ""; int i, j, k, result = 0, res1 = 0, res2 = 0; for(i = 0, k = 0; str1[i] != 0; i++) { for(j = 0, result = 0; str2[j] != 0 && result != 1; j++) { if(str1[i] == str2[j]) { temp[k] = str1[i]; k++; result = 1; } } } temp[k] = 0; for(i = 0; temp[i] != 0; i++) { str1[i] = temp[i]; } for(i = 0; i < 1023; i++, temp[i] = 0) { } temp[0] = 0; for(i = 0, k = 0; str2[i] != 0; i++) { for(j = 0, result = 0; str1[j] != 0 && result != 1; j++) { if(str2[i] == str1[j]) { temp[k] = str2[i]; k++; result = 1; } } } temp[k] = 0; for(i = 0; temp[i] != 0; i++) { str2[i] = temp[i]; } for(i = 0; i < 1023; i++, temp[i] = 0) { } for(i = 0, j = 0; str1[i] != 0; i++) { for(result = 0; str2[j] != 0 && result != 1; j++) { if(str1[i] == str2[j]) { temp[res1] = str1[i]; res1++; result = 1; } } } for(i = 0, j = 0; str2[i] != 0; i++) { for(result = 0; str1[j] != 0 && result != 1; j++) { if(str2[i] == str1[j]) { temp2[res2] = str2[i]; res2++; result = 1; } } } temp2[res2]; if(res1 > res2) { printf("%i\n", res1); fputs(temp, oup); } else { printf("%i\n", res2); fputs(temp2, oup); } for(i = 0; i < 1023; i++, temp[i] = 0) { } return; } int main(int argc, char **argv) { int i, result = 0; if(argc != 4) { printf("USAGE: <%s> \n", argv[0]); return -1; } inp1 = fopen(argv[1], "r"); inp2 = fopen(argv[2], "r"); oup = fopen(argv[3], "w+"); if(inp1 == NULL) { printf("---MAJOR PHAILURE---\nFile %s could not be opened for reading! *dying*\n", argv[1]); return -1; } if(inp2 == NULL) { printf("---MAJOR PHAILURE---\nFile %s could not be opened for reading! *dying*\n", argv[2]); return -1; } if(oup == NULL) { printf("---MAJOR PHAILURE---\nFile %s could not be opened for write+trunc *dying*\n", argv[3]); return -1; } printf("OK, now we have all the files...\n"); for(i = 0; result != -1; i++) { fgets(str1, 1000, inp1); fgets(str2, 1000, inp2); if(!feof(inp1)) { if(!feof(inp2)) { strip(); } } else { result = -1; } if(result == -1) { printf("Found EOF, stopping... (Well, duh!)\n"); result = -1; } } return 0; }