Alx09

Tema SDA Simplificata

Sep 29th, 2020 (edited)
750
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. typedef struct student {
  6.     char nume[20], adresa[20];
  7.     int nota, varsta, zi, luna, an;
  8.    
  9.    
  10. }stud;
  11.  
  12.  
  13. int main() {
  14.     FILE *f;
  15.     int i = 0, n;
  16.     f = fopen("in.txt", "r");
  17.     if (f == NULL) return 0;
  18.     stud stud[15];
  19.     while (fscanf(f, "%s",stud[i].nume) != EOF)
  20.     {
  21.         fscanf(f, "%d", &stud[i].nota);
  22.         fscanf(f, "%d", &stud[i].zi);
  23.         fscanf(f, "%d", &stud[i].luna);
  24.         fscanf(f, "%d", &stud[i].an);
  25.         fscanf(f, "%d", &stud[i].varsta);
  26.                 fscanf(f, "%*c");
  27.         fgets(stud[i].adresa, 30, f);
  28.         i++;
  29.     }
  30.     fclose(f);
  31.     f = fopen("ianuarie.txt", "w");
  32.     n = i;
  33.     for (i = 0; i < n; i++)
  34.         if (stud[i].luna == 1) {
  35.             fprintf(f, "%s ", stud[i].nume);
  36.             fprintf(f, "%d ", stud[i].nota);
  37.             fprintf(f, "%d ", stud[i].zi);
  38.             fprintf(f, "%d ", stud[i].luna);
  39.             fprintf(f, "%d ", stud[i].an);
  40.             fprintf(f, "%d ", stud[i].varsta);
  41.             fprintf(f, "%s", stud[i].adresa);
  42.         }
  43.    
  44.     fclose(f);
  45.  
  46.     return 0;
  47.  
  48. }
  49.  
RAW Paste Data