Advertisement
NoxScourge

Untitled

Aug 22nd, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdio.h>
  3.  
  4. int main()
  5. {
  6. int postoji = 0;
  7. FILE* f = fopen("C:\\Users\\Nox Scourge\\Desktop\\recenica.txt", "r");
  8. if (f == NULL) {
  9. printf("Fajl \"tekst.txt\" ne postoji u radnom folderu!\n"); //proverava da li fajl postoji
  10. return 0;
  11. }
  12. char rec[50], trenutnaRec[50];
  13. gets_s(rec); //uzimam recenicu iz fajla
  14.  
  15. while (!feof(f)){
  16. fscanf(f, "%s", trenutnaRec); //unosim koju rec zelim da vidim da li postoji
  17. if (strcmp(rec, trenutnaRec) == 0) //ako uporedi i vidi da su iste
  18. postoji = 1; //postoji
  19. }
  20. if (postoji) //prikazuje da li postoji ili ne
  21. printf("Rec postoji fajlu \"tekst.txt\"");
  22. else
  23. printf("Rec ne postoji u fajlu \"tekst.txt\"\n");
  24.  
  25. fclose(f);
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement