Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. #include <stdio.h>  //brchkalebis magivrad shegidzlia <>c
  2. #include <string.h>
  3. //studentis struqtura
  4. struct STUD
  5. {
  6.  
  7.     char name[100];
  8.     char surname[100];
  9.     char date[100];
  10.     int age;
  11.     int gpa;
  12.     __int64 id;
  13. };
  14. #define REGISTRATION 1  //preprocesoria, mexsierebashi arafers ar vwert
  15. #define SEARCH 2  //preprocesori nishnavs kompilatortan rom vmushaobt
  16. //# includes dros exe failis damzadebisas includedan rasac vigeb zedmets
  17. // gadakris kompilatori da rac schirdeba im funqciebs chaakerebs
  18. //
  19. //a.name ar chamoshlis tu ertxel mainc ar build an compile
  20. void main() {
  21.     char[100] filename = "sdb.qnt";
  22.     int state = 0;
  23.     struct STUD a;
  24.     memset((void*)&a, 0, sizeof(struct STUD));
  25.    
  26.     state = REGISTRATION;
  27.     if (state == REGISTRATION) {
  28.         strcpy(a.name, "saxeli");
  29.         strcpy(a.surname, "gvari");
  30.         strcpy(a.date, "12/12/2012");
  31.         a.age = 17;
  32.         a.gpa = 57;
  33.  
  34.         FILE *hf = 0;
  35.         hf = fopen(filename, "a");
  36.         for (int k = 0; k < 10000; k++)
  37.         {
  38.             sprintf(a.name, "sax_%d", k);
  39.             sprintf(a.surname, "gvari_%d", k);
  40.             sprintf(a.date, "%d/%d/%d", k % 30, k % 12, 1990 + k % 10);
  41.             a.id = 1000000 + k;
  42.             a.gpa = 40 + k % 50;
  43.             a.age = 1990 + k % 10;
  44.             fwrite(&a, sizeof(struct STUD), 1, hf);
  45.             //fwrite("2423423", 7, 1, hf);
  46.             //ujra aigos iqedan
  47.             //struqturas gadavcemt. vadzlevt struqturis misamarts da veubnebit ramdeni
  48.         }
  49.         fclose(hf);
  50.     }
  51.     else if (state == SEARCH)
  52.     {
  53.         hf = fopen(filename, "r");
  54.         //fileendoffile - sanam faili ar damtavrdeba
  55.         while (!feof(filename)) {
  56.             //1 bit aris chveni sazomi, 1,..
  57.             fread(&a, sizeof(a), 1, h);
  58.             if (a.age > 18) {
  59.                 //  %s - strikoni, &I64D - __int64
  60.                 printf("%s  &s  &I64D", a.name, a.surname, a.id);
  61.             }
  62.         }
  63.         fclose(hf);
  64.     }
  65.    
  66.  
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement