Hyluss

Operacje na plikach, tablice rejestracyjne

Jul 2nd, 2016
550
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. // operacje na plikach
  2.  
  3. // talbicerejestracyjne.cpp : Defines the entry point for the console application.
  4. //
  5.  
  6. #include "stdafx.h"
  7. #include <stdio.h>
  8. #include <conio.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #define _CRT_SECURE_NO_DEPRECATE
  12.  
  13.  
  14. struct structRejestracja {
  15. char woj[20];
  16. char miasto[20];
  17.  
  18. };
  19.  
  20.  
  21. int _tmain(int argc, _TCHAR* argv[])
  22. {
  23.  
  24. structRejestracja Rejestr [100];
  25. int i=0;
  26. int wynik;
  27.  
  28.  
  29.     FILE *wczytaj;
  30.     FILE *zapisz;
  31.  
  32.     wczytaj = fopen ("wrejestracja.txt","r");
  33.     if (wczytaj == NULL) {
  34.     perror ("blad");
  35.     exit (1);
  36.     }
  37.  
  38.     while (!feof (wczytaj)) {
  39.  
  40.         fscanf (wczytaj,"%s %s",&Rejestr[i].woj,&Rejestr[i].miasto);
  41.         printf ("%s %s\n",Rejestr[i].woj, Rejestr[i].miasto );
  42.  
  43.         wynik = strcmp ( "SY" , Rejestr[i].woj);
  44.        
  45.         if (0 == wynik)
  46.         {
  47.             i++ ;
  48.         }
  49.     }
  50.  
  51.     zapisz = fopen ("zrejestracja.txt","w");
  52.     if (zapisz == NULL) {
  53.     perror ("blad");
  54.     fclose (wczytaj);
  55.     exit (1);
  56.     }
  57.  
  58.     for (int j=0; j<i;j++) {
  59.     fprintf (zapisz,"%s %s \n",Rejestr[j].woj, Rejestr[j].miasto);
  60.     printf ("%s %s \n",Rejestr[j].woj, Rejestr[j].miasto);
  61.     }
  62.  
  63.     _getch();
  64.     return 0;
  65. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment