Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <locale.h>
- #include <string.h>
- #include <conio.h>
- struct Pupil
- {
- char name[50];
- char surname[50];
- int index;
- };
- struct List
- {
- struct List* prev;
- struct Pupil pupil;
- struct List* next;
- };
- struct List* active;
- struct List* head;
- struct List* last;
- void LoadContacts();
- void InsertAtHead(char *name, char *surname, int index);
- struct List* GetNew(char *name, char *surname, int index);
- void Print();
- void PrintPupil(int index);
- int Check(int index);
- int main ()
- {
- setlocale(LC_ALL, "polish_poland");
- char choice;
- char text[50];
- int index;
- char password[50];
- char pass_base[] = "abcd";
- int teachers_number;
- int Tnumber = 1234;
- int comparison;
- int check;
- int action;
- head = NULL;
- last = NULL;
- LoadContacts();
- printf(":::JSOS 3.0:::\n");
- while (1)
- {
- printf("Jaki rodzaj logowania wybierasz?\n");
- printf("1 - nauczyciel.\n");
- printf("2 - uczen.\n");
- printf("0 - wyjscie.\n");
- choice = getchar();
- while (getchar() != '\n');
- switch (choice)
- {
- case '1':
- while (1)
- {
- printf("Podaj numer identyfikacyjny.\n");
- scanf("%d", &teachers_number);
- if ((teachers_number) == (Tnumber))
- {
- Print();
- while (getchar() != '\n');
- printf("Wcisnij 0 aby sie wylogowac.\n");
- while (1)
- {
- scanf("%d", &action);
- if (action == 0)
- break;
- }
- if (action == 0)
- {
- while (getchar() != '\n');
- break;
- }
- }
- else
- {
- printf("Podales bledny numer.\n");
- }
- }
- break;
- case '2':
- printf("Podaj login - numer indeksu.\n");
- gets(text);
- sscanf(text, "%d", &index);
- printf("Podaj haslo.\n");
- gets(password);
- check = Check(index);
- comparison = strcoll(password, pass_base);
- if ((comparison = 0) && (check = 1))
- {
- PrintPupil(index);
- while (getchar() != '\n');
- printf("Wcisnij 0 aby sie wylogowac.\n");
- break;
- }
- else
- {
- printf("Podales bledne haslo lub zly login.\n");
- }
- break;
- case '0':
- goto end;
- break;
- default:
- printf("Nie wybrales zadnej z opcji logowania.\n");
- break;
- }
- }
- end:
- return 0;
- }
- void LoadContacts()
- {
- char text[150];
- char name[50];
- char surname[50];
- char index[50];
- int index_int;
- FILE *file;
- file = fopen("klasa.txt", "r");
- while (1)
- {
- fscanf(file, "%s", text);
- sscanf(text, "%[^;] ; %[^;] ; %[^;]", name, surname, index);
- sscanf(index, "%d", &index_int);
- if (fgetc(file) == EOF)
- {
- InsertAtHead(name, surname, index_int);
- break;
- }
- else
- {
- InsertAtHead(name, surname, index_int); //przekazanie danych do funkcji tworzacej strukture i dodajacej ja do listy
- }
- }
- fclose(file);
- }
- void InsertAtHead(char *name, char *surname, int index)
- {
- struct List* new = GetNew(name, surname, index);
- if (head == NULL) //jesli nic nie ma w liscie to nowy element jest pierwszym elementem
- {
- head = new;
- last = new;
- }
- else
- {
- head->prev = new;
- new->next = head;
- head = new;
- }
- }
- struct List* GetNew(char *name, char *surname, int index)
- {
- int i;
- struct List* new = (struct List*)malloc(sizeof(struct List));
- for (i = 0; i < 50; i++)
- {
- new->pupil.name[i] = name[i];
- }
- for (i = 0; i < 50; i++)
- {
- new->pupil.surname[i] = surname[i];
- }
- new->pupil.index = index;
- new->prev = NULL;
- new->next = NULL;
- return new;
- }
- void Print()
- {
- active = head;
- printf("Lista uczniow.\n");
- while (active != NULL)
- {
- printf("Imie: %s, Nazwisko: %s, Numer indeksu: %d\n", active->pupil.name, active->pupil.surname, active->pupil.index);
- active = active->next;
- }
- printf("\n");
- active = NULL;
- }
- void PrintPupil(int index)
- {
- active = head;
- while (active != NULL)
- {
- if (active->pupil.index == index)
- {
- printf("Imie i nazwisko: %s %s, Numer indeksu: %d\n", active->pupil.name, active->pupil.surname, active->pupil.index);
- }
- active = active->next;
- }
- printf("\n");
- active = NULL;
- }
- int Check(int index)
- {
- int flag = 0;
- active = head;
- while (active != NULL)
- {
- if (index == active->pupil.index)
- {
- flag = 1;
- }
- active = active->next;
- }
- active = NULL;
- return flag;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement