Advertisement
wilk_maciej

obecność z zapisem do pliku

Jan 10th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.39 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio_ext.h>
  5. #define max 999
  6.  
  7. typedef struct{
  8.     char *dane_osobowe;
  9.     int id;
  10. }osoba;
  11.  
  12. typedef struct myListElement{
  13.     struct myListElement *link;
  14.     osoba dane;
  15. }node;
  16.  
  17. typedef struct{
  18.     node *head;
  19.     int size;
  20. }myList;
  21.  
  22. char *uzupelnienie_char(void){
  23.     char bufor[max];
  24.     fgets(bufor, max, stdin);
  25.     char *tmp;
  26.     int wymiar;
  27.     wymiar=strlen(bufor)+1;
  28.     tmp=malloc (wymiar * sizeof(char));
  29.     if (!tmp){
  30.         perror("Coś poszło nie tak");
  31.         exit(2);
  32.     }
  33.     for (int i=0;i<wymiar;i++){
  34.         tmp[i]=bufor[i];
  35.     }
  36.     return tmp;
  37. }
  38.  
  39. int uzupelnienie_int(void){
  40.     int bufor;
  41.     char znak;
  42.     scanf ("%d", &bufor);
  43.     znak = getchar();
  44.     return bufor;
  45. }
  46.  
  47. void uzupelnienie_struktury(osoba *data){
  48.     printf("Podaj imię i nazwisko: ");
  49.     data -> dane_osobowe = uzupelnienie_char();
  50.     printf("Podaj identyfikator: ");
  51.     data -> id = uzupelnienie_int();
  52. }
  53.  
  54. void init(myList *list){
  55.     list -> head = NULL;
  56.     list -> size =0;
  57. }
  58.  
  59. void pushFront(myList *list, osoba data){
  60.   node *element = (node*) malloc (sizeof(node));
  61.     element -> link = list -> head;
  62.     element -> dane = data;
  63.     list -> head = element;
  64.     list -> size++;
  65. }
  66.  
  67. void dumpList(myList *list){
  68.     node *i;
  69.     for (i=list->head;i!=NULL;i=i->link){
  70.     printf("Dane: %sID:%d",i->dane.dane_osobowe, i->dane.id);
  71.     }
  72. }
  73.  
  74. void sprawdzacz(osoba *dane){
  75.     FILE * pFile;
  76.     int podejrzane_id;
  77.     int szukane_id;
  78.     szukane_id=dane->id;
  79.     pFile = fopen ("zablokowani", "r");
  80.     if (pFile == NULL){
  81.         perror ("Error opening file");
  82.     }
  83.     else {
  84.         while (!feof(pFile)){
  85.             (fscanf(pFile, "%d", &podejrzane_id));
  86.                 if (podejrzane_id == szukane_id){
  87.                     printf("Podejrzany\n");
  88.             }
  89.         }
  90.     fclose (pFile);
  91.     }
  92. }
  93.  
  94. void raportowanie(myList *list){
  95.     FILE *pFile;
  96.     node *i;
  97.     pFile=fopen("raport", "w");
  98.     if (pFile == NULL){
  99.         perror ("Ni ma");
  100.     }
  101.     else {
  102.         for (i=list->head;i!=NULL;i=i->link){
  103.             fprintf(pFile, "Dane: %sID:%d\n",i->dane.dane_osobowe, i->dane.id);
  104.         }
  105.     }
  106. }
  107.  
  108. int main(void){
  109.     int flag=1;
  110.     char odp;
  111.     osoba dane;
  112.     myList list;
  113.     init(&list);
  114.     while (flag<3){
  115.         uzupelnienie_struktury(&dane);
  116.         sprawdzacz(&dane);
  117.         pushFront(&list, dane);
  118.         flag++;
  119.         __fpurge(stdin);
  120.         printf ("Ktoś jeszcze? T/N\n");
  121.         odp=getchar();
  122.         __fpurge(stdin);
  123.         if (odp == "N" || odp == "n"){
  124.             flag=0;
  125.             break;
  126.  
  127.         }
  128.        
  129.     }
  130.     raportowanie(&list);
  131.     dumpList(&list);
  132.     return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement