int main() { int rows; int cols; char input[5]; int tall; int wide; initscr(); //initalize ncurses getmaxyx(stdscr, rows, cols); //get size of screen //Move to position, and print mvprintw(2, 3, "Enter the height: "); getstr(input); //get string from user, store in input tall = (int)strtol(input, NULL, 10); move(2,0); //move to beginning of line clrtoeol(); //clear line mvprintw(2, 3, "Enter the width: "); getstr(input); wide = (int)strtol(input, NULL, 10); erase(); //clear entire screen printRec(2,3,tall,wide); getch(); printRec(6,7,tall,wide); getch(); printRec(12,23,tall,wide); getch(); /* Pause for input. This really does nothing. It's just hear so you can see the screen before the program exits. Hit any key to continue*/ printMsg("End of program. Push any key to quit."); getch(); /* Important. Don't forget to do this: */ endwin(); //deinitalize ncurses return 0; }
void printRec(int *a,int *data,int start,int end,int index,int r) { if(index == r) { for(int i = 0; i < r; ++i) { printf("%d\t",data[i]); } printf("\n"); return; } for(int i = start; i <= end && end - i + 1 >= r - index; ++i) { data[index] = a[i]; printRec(a,data,i + 1,end,index + 1, r); } }
int main(void) { int a,i,details,s=0,j,c=0, len,chRec, records[100],r_count=0,copy; book lib[100]; char str[MAX_STR_LEN],ch,nullstr[20]={"\0"};; struct date due[MAX_STR_LEN]; char *psMenu[] = { "Please enter the ISBN of the book you want to add: ", "Please enter the book you want to remove: ", "Please enter the book you want to check out: ", "Please enter the book you want to check in: ", "Please enter the book you want details for: ", "All available books: ", "All checked out books: ", "GoodBye! Thank you for choosing the UTA Library." }; do { printf("\n"); printf(hLine); printf("\nWelcome to the University of Texas at Arlington Library\n"); printf(hLine); printf("\n1 - Add a new book\n2 - Remove a record\n3 - Check out a book\n4 - Check in a book\n"); printf("5 - Display all book details\n6 - Display all available books\n7 - Display all checked out books\n8 - Exit Program\n"); printf("\nEnter a selection: "); scanf("%d", &i); len=sizeof(records); copy=0; printf("\n"); switch(i) { case 1: if (r_count<10) { printf("\n%s",psMenu[i-1]); scanf("%d", &a); for(i=0;i<r_count;i++) { if (records[i]==a) { printf("\n\nERROR:// This book is already in the library database!//\n\n"); copy=1; break; } } if (copy==1) { break; } else records[r_count]=a; lib[r_count].nISBN=a; printf("\nPlease enter the book title: "); scanf(" %[^\n]s ",&lib[r_count].szTitle); printf("\nPlease enter the type of book: "); scanf(" %[^\n]s",&lib[r_count].szType); printf("\nPlease enter the book publisher: "); scanf(" %[^\n]s",&lib[r_count].szPub); printf("\nPlease enter the number of pages in the book: "); scanf("%d",&lib[r_count].nPage); printf("\nPlease enter the book price: $"); scanf("%f",&lib[r_count].nPrice); printf("\nPlease enter the year the book was published: "); scanf("%d",&lib[r_count].nPubyear); printf("\nPlease enter 1 if checked out or 0 if available: "); scanf("%d",&lib[r_count].nStatus); if (lib[r_count].nStatus==1) { s=1; printf("\nPlease enter the name of the person who checked this book out: "); scanf(" %[^\n]s",&lib[r_count].szName); printf("\nPlease enter the due date month: "); scanf("%d", &lib[r_count].due.nMonth); printf("\nPlease enter the due date day: "); scanf("%d", &lib[r_count].due.nDay); printf("\nPlease enter the due date year: "); scanf("%d", &lib[r_count].due.nYear); print_book(r_count, lib); printf("\nISBN %d < %s > was successfully added: \n",lib[r_count].nISBN, lib[r_count].szTitle); addbooktofile(r_count, lib, s); r_count++; break; } else { print_book(r_count, lib); printf("\nISBN %d < %s > was successfully added: \n",lib[r_count].nISBN, lib[r_count].szTitle); addbooktofile(r_count, lib, s); //printf("%d",r_count); debugging //printRec(records,r_count,lib); r_count++; break; } } else { printf("\nLibrary book shelf is full please check out or remove a book!\n"); break; } case 2: if (r_count>0) { printRec(records,r_count,lib); printf("\n%s",psMenu[i-1]); scanf("%d", &a); chRec=(a-1); printf("\n%s has been removed from the UTA Library Database\n\n ",lib[chRec].szTitle); for(j=a-1;j<r_count;j++) { if (j=r_count-1) { records[j]=' '; lib[j].nISBN=nullstr; strcpy(lib[j].szTitle,nullstr); strcpy(lib[j].szType,nullstr); strcpy(lib[j].szPub,nullstr); lib[j].nPage=nullstr; lib[j].nPrice=0; lib[j].nPubyear=nullstr; if (lib[j].nStatus==1) { lib[j].nStatus=nullstr; strcpy(lib[j].szName,nullstr); lib[j].due.nMonth=nullstr; lib[j].due.nDay=nullstr; lib[j].due.nYear=nullstr; } else { lib[j].nStatus=nullstr; } } else { records[j]=records[j+1]; strcpy(lib[j].nISBN,lib[j+1].nISBN); strcpy(lib[j].szTitle,lib[j+1].szTitle); strcpy(lib[j].szType,lib[j+1].szType); strcpy(lib[j].szPub,lib[j+1].szPub); lib[j].nPage=lib[j+1].nPage; lib[j].nPrice=lib[j+1].nPrice; lib[j].nPubyear=lib[j+1].nPubyear; if (lib[j].nStatus==1) { lib[j].nStatus=lib[j+1].nStatus; strcpy(lib[j].szName,lib[j+1].szName); lib[j].due.nMonth=lib[j+1].due.nMonth; lib[j].due.nDay=lib[j+1].due.nDay; lib[j].due.nYear=lib[j+1].due.nYear; } else { lib[j].nStatus=lib[j+1].nStatus; } } } r_count--; printf("\n"); printf("TESTER % d", j); break; } else { printf("\nRecords are empty please add a record!\n"); break; } case 3: if (r_count>0) { printRec(records,r_count,lib); printf("\n%s",psMenu[i-1]); scanf("%d", &a); printf("Please enter your name: "); scanf(" %s",&lib[a-1].szName); lib[a-1].nStatus=1; printf("\nPlease enter todays date: "); printf("Month: "); scanf("%d",&lib[a-1].due.nMonth); printf("Day: "); scanf("%d",&lib[a-1].due.nDay); printf("Year: "); scanf("%d",&lib[a-1].due.nYear); /*if (lib[a-1].due.nDay>19) lib[a-1].due.nDay=01; lib[a-1].due.nMonth=lib[a-1].due.nMonth+1; else lib[a-1].due.nDay+=10;*/ printf("\n"); printf("\nYour due date for %s is : %d/%d/%d\n\n", lib[a-1].szTitle, lib[a-1].due.nMonth, lib[a-1].due.nDay, lib[a-1].due.nYear); printRec(records,r_count,lib); break; } else { printf("\nRecords are empty please add a record!\n"); break; } case 4: if (r_count>0) { printcheckedout(records,r_count,lib); printf("\n%s",psMenu[i-1]); scanf("%d", &a); printf("Please enter your name: "); strcpy(lib[a-1].szName,nullstr); lib[a-1].nStatus=0; lib[a-1].due.nMonth=nullstr; lib[a-1].due.nDay=nullstr; lib[a-1].due.nYear=nullstr; printf("\nYour book %s has been checked in successfully.\n\n", lib[a-1].szTitle); printcheckedin(records,r_count,lib); break; } else { printf("\nRecords are empty please add a record!\n"); break; } case 5: printRec(records,r_count,lib); printf("\n%s",psMenu[i-1]); scanf("%d",&details); printf("\n\n"); print_book(details-1, lib); break; case 6: printf("\n%s\n\n",psMenu[i-1]); printcheckedin(records,r_count,lib); break; case 7: printf("\n%s\n\n",psMenu[i-1]); printcheckedout(records,r_count,lib); break; case 8: printf("\n%s\n\n",psMenu[i-1]); break; default: printf("\n\nError:// Please enter a valid selection 1-8: //\n\n"); } } while (i!=8); return 0; }
int main(void) { struct Hero mage = { "", MAGE, 450, 0, 50, 200, 30, 10, 1, 1, 0, 0, NULL, NULL }; struct Hero warrior = { "", WARRIOR, 550, 60, 0, 0, 5, 25, 1.3, 1, 0, 0, NULL, NULL }; struct Hero thief = { "", THIEF, 400, 60, 0, 0, 10, 15, 1, 1.2, 5, 0, NULL, NULL }; struct Hero bot1 = { "Mage", ANY, 500, 0, 45, 0, 15, 15, 1.4, 1.5, 10, 0, NULL, NULL }; struct Hero bot2 = { "Guard", ANY, 400, 65, 0, 0, 15, 35, 1.8, 1, 0, 0, NULL, NULL }; struct Hero bot3 = { "Black knight", ANY, 700, 100, 0, 0, 25, 25, 1, 1.2, 5, 0, NULL, NULL }; struct Hero * hero; struct Hero * bot = &(bot3); COORD posHead; int a; int b; int p = 0; int status = 0; int true = 0; const char * Interface[3] = { "New game", "Load", "Records" }; HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); metka: a = move (hConsole, 3, Interface, 7, hero, &(mage), &(warrior), &(thief)); switch (a){ case 0 : createHero(&(hero), &(mage), &(warrior), &(thief)); true = 1; break; case 1 : system("cls"); FILE * fp = NULL; printf("enter full name of file what you will open to load\n"); char str[30]; gets(str); fp = fopen(str, "r"); if (NULL == fp) status = 1; if (status == 0) { fscanf(fp, "%i", &(b)); switch (b) { case MAGE: hero = &(mage); break; case WARRIOR: hero = &(warrior); break; case THIEF: hero = &(thief); break; } int Weapon_type; int Armor_type; fscanf(fp, "%i %i %i", &(Weapon_type), &(Armor_type), &(hero->gold)); switch (Armor_type) { case -1: status = 1; break; case 6: hero->Armor = &(steel_armor); break; case 7: hero->Armor = &(mage_robe); break; case 8: hero->Armor = &(lether_armor); break; case 9: hero->Armor = &(dragon_armor); break; case 10: hero->Armor = &(arcgmage_robe); break; case 11: hero->Armor = &(elven_armor); break; } if (status != 1){ hero->health += hero->Armor->health; hero->damage += hero->Armor->damage; hero->mag_damage += hero->Armor->mag_damage; hero->mana += hero->Armor->mana; hero->magic_protect += hero->Armor->magic_protect; hero->armor += hero->Armor->armor; hero->critical_damage += hero->Armor->critical_damage - 1; hero->critical_chanse += hero->Armor->critical_chanse; } switch (Weapon_type) { case -1: status = -1; break; case 0: hero->Weapon = &(steel_sword); break; case 1: hero->Weapon = &(magic_stick); break; case 2: hero->Weapon = &(steel_dagger); break; case 3: hero->Weapon = &(great_sword); break; case 4: hero->Weapon = &(wood_scepter); break; case 5: hero->Weapon = &(thief_dagger); break; } if (status != -1){ hero->health += hero->Weapon->health; hero->damage += hero->Weapon->damage; hero->mag_damage += hero->Weapon->mag_damage; hero->mana += hero->Weapon->mana; hero->magic_protect += hero->Weapon->magic_protect; hero->armor += hero->Weapon->armor; hero->attack_speed = hero->Weapon->attack_speed; hero->critical_damage += hero->Weapon->critical_damage - 1; hero->critical_chanse += hero->Weapon->critical_chanse; } true = 1; } else printf("error input"); fclose(fp); break; case 2 : printRec(); goto metka;break; } while (true) { shop(hero, &(mage), &(warrior), &(thief)); true = battle(hero, &(bot1), &(bot2), &(bot3)); if (true == 2) ; else if (true) printf("WIN\n"); else printf("LOSE\n"); getchar(); } system("cls"); posHead.X = 34; posHead.Y = 10; SetConsoleCursorPosition(hConsole, posHead); SetConsoleTextAttribute(hConsole, FOREGROUND_RED); puts("GAME OVER"); posHead.Y = 11; SetConsoleCursorPosition(hConsole, posHead); printf("your result is %i", hero->gold); posHead.Y++; SetConsoleCursorPosition(hConsole, posHead); printf("enter your nickname\n"); char nick[20]; posHead.Y++; SetConsoleCursorPosition(hConsole, posHead); gets(nick); if (nick[0] == '\0') strcpy(nick, "noName"); int record[10]; char temp[10][20]; FILE * fp = NULL; fp = fopen("reclab4.txt", "r"); if (NULL == fp) return 0; for (int i = 0; i < 10; i++){ fscanf(fp, "%i %s", &record[i], temp[i]); //printf("%i. %8i %s\n", i + 1, record, nick); if (record[i] > hero->gold) p = i; } fclose(fp); fp = fopen("reclab4.txt", "w"); for (int i = 0; i < 10; i++){ if (p == i - 1) fprintf(fp, "%i %s\n", hero->gold, nick); fprintf(fp, "%i %s\n", record[i], temp[i]); } SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN); getchar(); fclose(fp); return EXIT_SUCCESS; }
void printCombination(int *a,int n,int r) { int result[r]; printRec(a,result,0,n - 1,0, r); }
int main (void) { /* program to coordinate the menu options and calls the requested function */ struct node * first = NULL; /* pointer to the first list item */ char option[strMax]; /* user response to menu selection */ printf ("Program to Maintain a List of Names\n"); while (1) { /* print menu options */ printf ("Options available\n"); printf ("I - Insert a name into the list\n"); printf ("D - Delete a name from the list\n"); printf ("C - Count the number of items on the list\n"); printf ("F - Move an item to the front of the list\n"); printf ("L - Print the last item on the list (iteratively)\n"); printf ("M - Print the last item on the list (recursively)\n"); printf ("P - Print the names on the list (iteratively)\n"); printf ("S - Print the names on the list (recursively)\n"); printf ("R - Print the names in reverse order\n"); printf ("Q - Quit\n"); /* determine user selection */ printf ("Enter desired option: "); scanf ("%s", option); switch (option[0]) { case 'I': case 'i': addName(&first); break; case 'D': case 'd': deleteName(&first); break; case 'C': case 'c': countList(first); break; case 'F': case 'f': putFirst(&first); break; case 'L': case 'l': printLast(first); break; case 'M': case 'm': printLastRec(first); break; case 'P': case 'p': print(first); break; case 'S': case 's': printRec(first); break; case 'R': case 'r': printReverse(first); break; case 'Q': case 'q': printf ("Program terminated\n"); return 0; break; default: printf ("Invalid Option - Try Again!\n"); continue; } } }