The text file contains words. Remove all duplicate words from a file.

#include <stdio.h> int main(int argc, char *argv[]) { int i=0,count=0; char a[1000]; char b[100][1000]; FILE *file=fopen("1.txt", "r"); FILE *file2=fopen("2.txt", "w"); //извлекаем из файла в массив for(int i=0;!feof(file);i++){ fscanf(file,"%c",&a[i]); count++; } //записываем в файл по слову в каждую строку for(int i=0;i<count-1;i++){ if(a[i]==*" "){ fprintf(file2,"\n"); } else{ fprintf(file2,"%c",a[i]); } } fclose(file2); FILE *file3=fopen("2.txt", "r"); while(!feof(file3)){ fscanf(file3,"%s",b[i]); printf("%d) %s ",i+1,b[i]); i++; } fclose(file); fclose(file3); FILE *del_file = fopen("1.txt","w+"); for(int j=0;j<i;j++){ printf("'%s' and '%s'\n",b[j],b[j+1]); if(b[j] == b[j+1]){ //эти строки не хотят сравниваться printf("true %s ",b[j]); } fprintf(del_file,"%s ",b[j]); } fclose(del_file); printf("\n"); return 0; } 

I know what I’m doing in an idiotic way, but I don’t know how differently, the algorithm is as follows: we literally read data from a file into an array, write a word from another array, write a word to each line, then read them into lines, then read array of strings, the problem is that the strings do not compare with each other, the condition does not pass (it is marked in the code), what can it be and how to fix it?

  • four
    Potmou is not a string comparison, but a pointer comparison. - iksuy
  • @alexoander, I did not make out, because this is only a problem, and the author asks how to fix it. - iksuy
  • one
    Do you want only adjacent (consecutive) repeats to delete? Or in the entire file to look for duplicates? Should the result keep the word order in the source file? What is the word? For example, how many different words in the string: "word word word."? (dot at the end) If space is separated, can non-ascii spaces occur? Give a clear example of I / O. - jfs
  • @VadimFroz If you think you have found a solution, post it as your answer to get comments about the solution and help other people with the same problem. This is clearly welcome - jfs
  • one
    What is the encoding of the text in the file? What are "duplicate words"? Is morphemic transformation (file - file, etc.) taken into account? If taken into account, what is the maximum Levenshtein distance allowed? What to do with the first word from the list? Leave? The task for the creative! - 0andriy

0