Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(int argc, char** argv)
- {
- int lenReda = 0;
- char *novRed = 0, c;
- FILE* f = fopen("test.txt", "r");
- if (!f)
- {
- printf("Fajl nije pronadjen!");
- getchar();
- return 1;
- }
- while (!feof(f))
- {
- lenReda = 0;
- // ucitamo iz fajla slovo po slovo dok ne dodjemo do karaktera za nov red
- while ( (c = fgetc(f)) != '\n' && !feof(f))
- {
- novRed = realloc(novRed, (++lenReda + 1) * sizeof(char));
- novRed[lenReda - 1] = c;
- }
- // moramo da dodamo null terminator na kraj ucitanog stringa
- novRed[lenReda] = '\0';
- printf("%s\n", novRed);
- // argv[0] je putanja do fajla
- // prvi argument je argv[1]
- if (strcmp(novRed, argv[1]) == 0)
- printf("Linije se poklapaju.\n\n");
- else
- printf("Linije se ne poklapaju.\n\n");
- // obrisi iz memorije
- free(novRed);
- novRed = 0;
- }
- // zatvorimo fajl
- fclose(f);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement