Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4.  
  5. struct recenica
  6. {
  7.     char rec[30];
  8. };
  9.  
  10. main()
  11. {
  12.     int i, n = 0;
  13.     struct recenica r;
  14.     FILE * fp;
  15.  
  16.     fp = fopen("rec.txt", "w");
  17.  
  18.     if (fp == NULL)
  19.     {
  20.         printf("Greska pri otvaranju datoteke.");
  21.         exit(1);
  22.     }
  23.  
  24.     printf("Upisi neku recenicu: ");
  25.     gets(r.rec);
  26.  
  27.     fwrite(&r, sizeof(struct recenica), 1, fp);
  28.     fclose(fp);
  29.  
  30.     fp = fopen("rec.txt", "r");
  31.  
  32.     fread(&r, sizeof(struct recenica), 1, fp);
  33.  
  34.     for (i = 0; i < 30; i++)
  35.     {
  36.         if (r.rec[i] != '\0')
  37.         {
  38.             n++;
  39.         }
  40.         else
  41.         {
  42.             break;
  43.         }
  44.     }
  45.  
  46.     printf("\nRecenica ima %d znakova.", n);
  47.  
  48.     fclose(fp);
  49.  
  50.     getch();
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement