Untitled
unknown
plain_text
2 years ago
1.1 kB
8
Indexable
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
FILE *input = fopen("input.txt", "r");
if (input == NULL) {
perror("Cannot open the input file");
return 1;
}
FILE *output = fopen("output.txt", "w");
if (output == NULL) {
perror("Cannot create the output file");
fclose(input);
return 1;
}
char line[1000];
char previousLines[1000][1000];
int numLines = 0;
while (fgets(line, sizeof(line), input)) {
int isDuplicate = 0;
// Check if the current line is a duplicate
for (int i = 0; i < numLines; i++) {
if (strcmp(line, previousLines[i]) == 0) {
isDuplicate = 1;
break;
}
}
if (!isDuplicate) {
strcpy(previousLines[numLines], line);
numLines++;
fputs(line, output);
}
}
fclose(input);
fclose(output);
printf("Unique lines extracted successfully into 'output.txt'\n");
return 0;
}
Editor is loading...