Pp9

wielokrotne zapisywanie do pliku

Pp9
Dec 5th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define N 20
  4.  
  5. struct str
  6. {
  7.     char imie[N], nazw[N];
  8.     int wiek;
  9. };
  10.  
  11. int czy_dalej();
  12.  
  13. int main()
  14. {
  15.     FILE *fle;
  16.     fle=fopen("t.txt","wt");
  17.  
  18.     while (czy_dalej())
  19.     {
  20.         struct str str1;
  21.         //if (czy_dalej()){fclose(fle); return 0;}
  22.  
  23.         printf("\nPodaj imie: ");
  24.         scanf("%s", str1.imie);
  25.         realloc(str1.imie,strlen(str1.imie));
  26.  
  27.  
  28.         printf("\nPodaj nazwisko: ");
  29.         scanf("%s", &str1.nazw);
  30.         realloc(str1.nazw,strlen(str1.nazw));
  31.         printf("\nPodaj wiek: ");
  32.         scanf("%d", &str1.wiek);
  33.  
  34.         fprintf(fle, "%s %s %d\n", str1.imie, str1.nazw, str1.wiek);
  35.  
  36.     }
  37.     fclose(fle);
  38.     return 0;
  39. }
  40.  
  41. int czy_dalej() //cos zepsute (nie pozwala na wpisanie litery drugi raz)
  42. {
  43.     char x;
  44.     printf("Czy dalej? (Y,N): ");
  45.     scanf("%c", &x);
  46.     if ((x=='y')||(x=='Y')) return 1;
  47.     else return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment