I was wondering if someone could give me some assistance with my program. What I have right now is a file called 'duplicates.txt' which contains the following integers I maually entered:
1
1
2
3
3
3
4
5
I can read the file and write the file, the problem is I need to only write one of each number to the written file called 'non-duplicates.txt'. I don't know where to start with this. Here is the code that I currently have. Any help would be appreciated.
Code:
#include <stdio.h>
int main(void)
{
FILE *file;
char buffer[10];
file = fopen("duplicates.txt", "r");
while (fgets(buffer, sizeof(buffer), file))
printf("%s", buffer);
return(0);
fclose(file);
file = fopen("non-duplicates.txt", "w");
fwrite(buffer, sizeof(buffer), 10, file);
fclose(file);
}