Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <unistd.h>
- char *dobby= ""
- " / \\\n"
- "/- (*) |*)\\\n"
- "|/\\. _>/\\|\n"
- " \\__/ |\\\n"
- " _| |_ \\-/\n"
- " /|\\__|\\ //\n"
- " |/| |\\//\n"
- " ||| | ~'\n"
- " ||| __|\n"
- " /_\\| ||\n"
- " \\_/| ||\n"
- " |7 |7\n"
- " || ||\n"
- " || ||\n"
- " /\\ \\ \\ \n"
- " ^^^^ ^^^ \n";
- struct Wizard{
- char name[12];
- char house[12];
- int age;
- };
- void winner(){
- uid_t euid;
- euid = geteuid();
- setresuid(euid,euid,euid);
- system("cat flag");
- }
- struct Hogwarts{
- struct Wizard wizards[10];
- unsigned int amount;
- unsigned int max_wizards;
- };
- void flushh(){
- int c;
- while((c = getchar()) != '\n' && c != EOF);
- }
- void init_hogwarts(struct Hogwarts *hogwarts){
- hogwarts->amount = 0;
- hogwarts->max_wizards = 10;
- }
- int add_wizard(struct Hogwarts *hogwarts){
- unsigned int index = hogwarts->amount;
- if(index >= hogwarts->max_wizards){
- printf("Hogwarts is full right now, please try next year :(\n");
- return 0;
- }
- printf("Enter wizard name: \n");
- fgets(hogwarts->wizards[index].name, 12, stdin);
- printf("Enter wizard house: \n");
- fgets(hogwarts->wizards[index].house, 12, stdin);
- printf("Enter wizard age: \n");
- scanf("%d", &(hogwarts->wizards[index].age));
- flushh();
- hogwarts->amount++;
- return 1;
- }
- void print_all_wizards(struct Hogwarts *hogwarts){
- int num = hogwarts->amount;
- for(int i = 0; i < num; ++i){
- struct Wizard *wiz = &(hogwarts->wizards[i]);
- printf("---------------------------------------\n\n");
- printf("[%d] Name: %s \n", i, wiz->name);
- printf("[%d] House: %s \n", i, wiz->house);
- printf("[%d] Age: %d \n", i, wiz->age);
- printf("---------------------------------------\n\n");
- }
- }
- void modify_wizard(struct Hogwarts *hogwarts){
- int index;
- printf("What's the wizard index you want to modify?\n");
- scanf("%d", &index);
- flushh();
- printf("Enter wizard name: \n");
- fgets(hogwarts->wizards[index].name, 12, stdin);
- printf("Enter wizard house: \n");
- fgets(hogwarts->wizards[index].house, 12, stdin);
- printf("Enter wizard age: \n");
- scanf("%d", &(hogwarts->wizards[index].age));
- flushh();
- }
- int main(int argc, char **argv){
- struct Hogwarts hogwarts;
- char action[2];
- init_hogwarts(&hogwarts);
- printf("Welcome to Hogwarts!\n\n");
- printf("%s\n\n",dobby);
- printf("Please choose an action:\n\n");
- while(1){
- printf("[0] Create a new wizard:\n");
- printf("[1] Modify an exisiting wizard:\n");
- printf("[2] Print all wizards\n\n");
- printf("[3] Exit\n\n");
- fgets(action, 2, stdin);
- flushh();
- switch(action[0]) {
- case '0':
- add_wizard(&hogwarts);
- break;
- case '1':
- modify_wizard(&hogwarts);
- break;
- case '2':
- print_all_wizards(&hogwarts);
- break;
- case '3':
- exit(0);
- break;
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement