Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- struct recenica
- {
- char rec[30];
- };
- main()
- {
- int i, n = 0;
- struct recenica r;
- FILE * fp;
- fp = fopen("rec.txt", "w");
- if (fp == NULL)
- {
- printf("Greska pri otvaranju datoteke.");
- exit(1);
- }
- printf("Upisi neku recenicu: ");
- gets(r.rec);
- fwrite(&r, sizeof(struct recenica), 1, fp);
- fclose(fp);
- fp = fopen("rec.txt", "r");
- fread(&r, sizeof(struct recenica), 1, fp);
- for (i = 0; i < 30; i++)
- {
- if (r.rec[i] != '\0')
- {
- n++;
- }
- else
- {
- break;
- }
- }
- printf("\nRecenica ima %d znakova.", n);
- fclose(fp);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement