Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdio_ext.h>
- #define max 999
- typedef struct{
- char *dane_osobowe;
- int id;
- }osoba;
- typedef struct myListElement{
- struct myListElement *link;
- osoba dane;
- }node;
- typedef struct{
- node *head;
- int size;
- }myList;
- char *uzupelnienie_char(void){
- char bufor[max];
- fgets(bufor, max, stdin);
- char *tmp;
- int wymiar;
- wymiar=strlen(bufor)+1;
- tmp=malloc (wymiar * sizeof(char));
- if (!tmp){
- perror("Coś poszło nie tak");
- exit(2);
- }
- for (int i=0;i<wymiar;i++){
- tmp[i]=bufor[i];
- }
- return tmp;
- }
- int uzupelnienie_int(void){
- int bufor;
- char znak;
- scanf ("%d", &bufor);
- znak = getchar();
- return bufor;
- }
- void uzupelnienie_struktury(osoba *data){
- printf("Podaj imię i nazwisko: ");
- data -> dane_osobowe = uzupelnienie_char();
- printf("Podaj identyfikator: ");
- data -> id = uzupelnienie_int();
- }
- void init(myList *list){
- list -> head = NULL;
- list -> size =0;
- }
- void pushFront(myList *list, osoba data){
- node *element = (node*) malloc (sizeof(node));
- element -> link = list -> head;
- element -> dane = data;
- list -> head = element;
- list -> size++;
- }
- void dumpList(myList *list){
- node *i;
- for (i=list->head;i!=NULL;i=i->link){
- printf("Dane: %sID:%d",i->dane.dane_osobowe, i->dane.id);
- }
- }
- void sprawdzacz(osoba *dane){
- FILE * pFile;
- int podejrzane_id;
- int szukane_id;
- szukane_id=dane->id;
- pFile = fopen ("zablokowani", "r");
- if (pFile == NULL){
- perror ("Error opening file");
- }
- else {
- while (!feof(pFile)){
- (fscanf(pFile, "%d", &podejrzane_id));
- if (podejrzane_id == szukane_id){
- printf("Podejrzany\n");
- }
- }
- fclose (pFile);
- }
- }
- void raportowanie(myList *list){
- FILE *pFile;
- node *i;
- pFile=fopen("raport", "w");
- if (pFile == NULL){
- perror ("Ni ma");
- }
- else {
- for (i=list->head;i!=NULL;i=i->link){
- fprintf(pFile, "Dane: %sID:%d\n",i->dane.dane_osobowe, i->dane.id);
- }
- }
- }
- int main(void){
- int flag=1;
- char odp;
- osoba dane;
- myList list;
- init(&list);
- while (flag<3){
- uzupelnienie_struktury(&dane);
- sprawdzacz(&dane);
- pushFront(&list, dane);
- flag++;
- __fpurge(stdin);
- printf ("Ktoś jeszcze? T/N\n");
- odp=getchar();
- __fpurge(stdin);
- if (odp == "N" || odp == "n"){
- flag=0;
- break;
- }
- }
- raportowanie(&list);
- dumpList(&list);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement