online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <stdio.h> #include <string.h> #include <conio.h> int main() { //---------------------structure of book-----------------------// struct books { char name[30]; int book_number; char author[30]; char genre[20]; int book_count; }; struct books b[50]; strcpy(b[2].name,"Business correspondence and report writing"); b[2].book_count=0; strcpy(b[2].author, "Krishna Mohan"); strcpy(b[2].genre, "Education"); strcpy(b[3].name,"The Diary of a Young Girl"); b[3].book_count=8; strcpy(b[3].author, "Anne Frank"); strcpy(b[3].genre, "Autobiography"); strcpy(b[4].name,"House of Secrets"); b[4].book_count=7; strcpy(b[4].author, "Chris Columbus"); strcpy(b[4].genre, "Adventure Fiction"); strcpy(b[5].name,"Wings of fire"); b[5].book_count=4; strcpy(b[5].author, "Dr. A.P.J. Abdul Kalam"); strcpy(b[5].genre, "Autobiography"); strcpy(b[6].name,"Concept of Physics"); b[6].book_count=10; strcpy(b[6].author, "H.C. Verma"); strcpy(b[6].genre, "Education"); strcpy(b[7].name,"Long Walk to Freedom"); b[7].book_count=4; strcpy(b[7].author, "Nelson Mandela"); strcpy(b[7].genre, "Autobiography"); strcpy(b[8].name,"Thermal Physics"); b[8].book_count=5; strcpy(b[8].author, "S.P. Taneja"); strcpy(b[8].genre, "Education"); strcpy(b[9].name,"The Invisible Man"); b[9].book_count=4; strcpy(b[9].author, "H.G. Wells"); strcpy(b[9].genre, "Novel"); strcpy(b[10].name,"Higher Engineering Mathematics"); b[10].book_count=8; strcpy(b[10].author, "B.S. Grewal"); strcpy(b[10].genre, "Education"); strcpy(b[11].name,"Rich Dad Poor Dad"); b[11].book_count=3; strcpy(b[11].author, "Robert Kiyosaki"); strcpy(b[11].genre, "Non-Fiction"); strcpy(b[12].name,"Three Men in a Boat"); b[12].book_count=6; strcpy(b[12].author, "Jerome K. Jerome"); strcpy(b[12].genre, "Novel"); strcpy(b[13].name,"Computer Science with Python"); b[13].book_count=4; strcpy(b[13].author, "Sumita Arora"); strcpy(b[13].genre, "Education"); strcpy(b[14].name,"The Alchemist"); b[14].book_count=8; strcpy(b[14].author, "Paulo Coelho"); strcpy(b[14].genre, "Novel"); strcpy(b[15].name,"Objective Mathematics"); b[15].book_count=4; strcpy(b[15].author, "R.D. Sharma"); strcpy(b[15].genre, "Education"); char requested_book_name[30][100]; char requested_book_author[30][100]; // requested book variable declaration// int requested_book_count=0; int number_of_requested_books; int variable_for_signup_counter_loop=2; int variable_for_customer_details=1; char flush[30]; char dob[30][10]={"31032003","04092003"}; char address[30][30]={"sector-57","sector-23"}; char name[30][25]={"Nischal","yashika"}; int switch_case,requested_books_number; //declaration of variables which// //are used throughout the code// struct member { char new_signup_username_array[15]; char new_signup_password_array[15]; //declaration of member signin details// int issued_book[5]; int book_counter; int date[15]; int month[15]; int year[15]; }; struct member m[500]; for(int loop_count=1;loop_count<=variable_for_signup_counter_loop;loop_count++) { m[loop_count].book_counter=0; } strcpy(m[1].new_signup_username_array,"flush"); strcpy(m[1].new_signup_password_array,"flush"); strcpy(m[2].new_signup_username_array,"nis31032003"); strcpy(m[2].new_signup_password_array,"googlegmail"); //declaring pre-declared login credentials// int issue_books_book_number; char issue_books_username[15]; //declaring variables for book issue portal// char issue_books_date[10]; int issue_books_username_check; int return_books_username_check; char return_book_username[15]; int return_books_book_number; char return_books_username[15]; int username_match_issue; int username_match_return; int username_match_binary_issue; int username_match_binary_return; int items_count=0; home: //label 1// printf("\n\t\t\t\t\t LIBRARY PORTAL \n\n"); printf(" \t\t\t\t\tLogin\t\t\t\t press 1\n \t\t\t\t\tRules Of The Library\t\t press 2\n \t\t\t\t\tNew Member Signup\t\t press 3\n \t\t\t\t\tLost and Found\t\t\t press 4\n \t\t\t\t\tAbout The Program\t\t press 5\n"); scanf("%d",&switch_case); switch(switch_case) { case 1: //login page// { int login,match_pass_customer,match_username_customer,match_pass_administration,match_username_administration; char customer_username[30]; char customer_pass[15]; char customer_password_original[]="googlegmail"; char customer_username_original[]="Agr04062004"; char administration_username[30]; char administration_pass[15]; char administraion_username_original[]="admin"; char administration_password_orignal[]="admin.main"; printf("\t\t\t\t\t\t\t Login Page \t\t\t\n\n"); printf(" Administration login\t press 1\n Customer login\t\t press 2\n"); printf("\n\t\t\t\t\t\t\t\t\t\t Press 0 to return to previous page\n"); scanf("%d",&login); switch(login) { case 1: { printf("\n ADMINISTRATION LOGIN PAGE\n"); printf("\n Please enter your login credentials\n\n"); login_administraion_re: printf("\n USERNAME: "); scanf("%s",administration_username); printf("\n PASSWORD: "); scanf("%s",administration_pass); match_pass_administration= strcmp(administration_password_orignal,administration_pass); match_username_administration= strcmp(administraion_username_original,administration_username); if(match_pass_administration!=0 && match_username_administration!=0) { printf("\n\n INCORRECT USERNAME OR PASSWORD"); goto login_administraion_re; } else { int administration_login_input,return_costs; printf(" \n\nLOGIN SUCCESSFULL !!!\n"); printf(" \n WELCOME TO ADMINISTRATION PAGE\n\n\n"); administration_page_main: //administration log in page printf(" Customer Details Press 1\n"); printf(" Requested Books Press 2\n"); printf(" Issue Books Press 3\n"); printf(" To Return To The Home Page Press 0\n"); administraion_page_main_error: scanf("%d",&administration_login_input); switch(administration_login_input) { case 1: { printf("\n\n CUSTOMER DETAILS"); printf("\nS.no Name Address DOB"); printf("\n-------------------------------------------------------------------------"); for(int customer_details=0;customer_details<=variable_for_customer_details;customer_details++) { printf("\n%d %s %s %s",customer_details+1,name[customer_details],address[customer_details],dob[customer_details]); } printf("\n\n Press 0 to return to the previous page"); error_customer_details: scanf("%d",&return_costs); if(return_costs==0) { goto administration_page_main; } else { printf(" ERROR !!! INVALID INPUT"); goto error_customer_details; } } case 2: { int requested_books_input; printf(" REQUESTED BOOKS"); printf("\n\n\n\n"); printf(" S.no. Name Of The Books Author Name \n"); printf("-------------------------------------------------------------------------------\n"); for(number_of_requested_books=1;number_of_requested_books<=requested_book_count;number_of_requested_books++) printf(" %d %s %s \n",number_of_requested_books,requested_book_name[number_of_requested_books],requested_book_author[number_of_requested_books]); printf("\n\n Press 0 to return to the previous page"); error_requested_books: scanf("%d",&requested_books_input); if(requested_books_input==0) { goto administration_page_main; } else { printf(" ERROR !!! INVALID INPUT"); goto error_requested_books; }; } case 3: { int fd,fm,fy,sd,sm,sy,ty,tday,rday,i,r,c1,c2; int username_match_binary,book_issue_input; printf("\n BOOK ISSUE "); printf("\n\n ISSUE A NEW BOOK Press1"); printf("\n Return a Book Press2"); printf("\n Press 0 to return to the previous page\n"); book_issue_error1: scanf("%d",&book_issue_input); switch(book_issue_input) { case 0: { goto administration_page_main; } case 2: { int return_book_data_check; return_book_error1: printf("\n RETURN BOOK"); printf("\n\n Username Of The Member: "); scanf("%s",&return_books_username); printf("\n Date Of Return: "); scanf("%d %d %d",&sd,&sm,&sy); // insert variables for return date.........//and scan them...// printf("\n Book Number: "); scanf("%d",&return_books_book_number); issue_books_username_check=0; while (issue_books_username_check<=500) { username_match_issue=strcmp(issue_books_username,m[issue_books_username_check].new_signup_username_array); if(username_match_issue==0) { username_match_binary_return=1; break; } else { issue_books_username_check++; } } if(username_match_binary_return!=1) { printf("\n USERNAME NOT FOUND"); goto return_book_error1; } else { return_book_data_check=0; while(return_book_data_check<=15) { if(return_books_book_number==m[issue_books_username_check].issued_book[return_book_data_check]) { m[issue_books_username_check].issued_book[return_book_data_check]=0; b[return_books_book_number].book_count++; m[issue_books_username_check].book_counter--; //time function fd=m[issue_books_username_check].date[return_books_book_number]; fm=m[issue_books_username_check].month[return_books_book_number]; fy=m[issue_books_username_check].year[return_books_book_number]; ty=fy-sy; tday=ty*365; tday--; fy--; for(i=sy;i<=fy;i++) { r=i%4; if(r==0) { tday++; } } c1=--fm; switch(c1) { case 1:tday=tday+31;break; case 2:tday=tday+59;fy++;r=fy%4;if(r==0){tday++;}break; case 3:tday=tday+90;fy++;r=fy%4;if(r==0){tday++;}break; case 4:tday=tday+120;fy++;r=fy%4;if(r==0){tday++;}break; case 5:tday=tday+151;fy++;r=fy%4;if(r==0){tday++;}break; case 6:tday=tday+181;fy++;r=fy%4;if(r==0){tday++;}break; case 7:tday=tday+212;fy++;r=fy%4;if(r==0){tday++;}break; case 8:tday=tday+243;fy++;r=fy%4;if(r==0){tday++;}break; case 9:tday=tday+273;fy++;r=fy%4;if(r==0){tday++;}break; case 10:tday=tday+304;fy++;r=fy%4;if(r==0){tday++;}break; case 11:tday=tday+334;fy++;r=fy%4;if(r==0){tday++;}break; } tday=tday+fd; c2=--sm; switch(c2) { case 1:rday=31;break; case 2:rday=59;r=sy%4;if(r==0){rday++;}break; case 3:rday=90;r=fy%4;if(r==0){rday++;}break; case 4:rday=120;r=fy%4;if(r==0){rday++;}break; case 5:rday=151;r=fy%4;if(r==0){rday++;}break; case 6:rday=181;r=fy%4;if(r==0){rday++;}break; case 7:rday=212;r=fy%4;if(r==0){rday++;}break; case 8:rday=243;r=fy%4;if(r==0){rday++;}break; case 9:rday=273;r=fy%4;if(r==0){rday++;}break; case 10:rday=304;r=fy%4;if(r==0){rday++;}break; case 11:rday=334;;r=fy%4;if(r==0){rday++;}break; } rday=rday+sd; tday=tday-rday; tday++; if(tday<(-14)) { int fine=(-5)*tday; int days_fine=(-1)*tday; printf("\n\t\t\t\t THE BOOK IS OVERDUE BY %d DAYS \n\t\t\t\t PLEASE PAY A FINE OF Rs.%d\n ",days_fine,fine); } //time function printf(" THE BOOK HAS BEEN RETURNED\n"); goto administration_page_main; } else { if(return_book_data_check<15) { return_book_data_check++; } else { printf(" THIS BOOK WAS NOT ISSUED"); goto administration_page_main; } } } printf("\n your book has been returned"); goto administration_page_main; } } case 1: { int date_input,month_input,year_input; book_issue_error2: gets(flush); printf("\nUsername of the member: "); scanf("%s",&issue_books_username); printf("\n Book Number: "); scanf("%d",&issue_books_book_number); printf("\nDate of issue: "); scanf("%d %d %d",&date_input,&month_input,&year_input); issue_books_username_check=0; while (issue_books_username_check<=500) { username_match_issue=strcmp(issue_books_username,m[issue_books_username_check].new_signup_username_array); if(username_match_issue==0) { username_match_binary_issue=1; break; } else { issue_books_username_check++; } } if(username_match_binary_issue==1) { m[issue_books_username_check].book_counter++; if(m[issue_books_username_check].book_counter>=5) { printf(" BOOK ISSUE LIMIT EXCEEDED !!!\n YOU HAVE ALREADY ISSUED 5 BOOKS "); m[issue_books_username_check].book_counter--; } else { //identifier// Highly important// b[issue_books_book_number].book_count--; if(b[issue_books_book_number].book_count<0) { printf("\n\t\t\t\t\tThe book is currently not available "); b[issue_books_book_number].book_count++; } else { m[issue_books_username_check].issued_book[m[issue_books_username_check].book_counter]=issue_books_book_number; m[issue_books_username_check].date[issue_books_book_number]=date_input; m[issue_books_username_check].month[issue_books_book_number]=month_input; m[issue_books_username_check].year[issue_books_book_number]=year_input; printf("\n The Book Has been Successfully Issued."); } } break; } else { printf("\n Username does not exist"); goto book_issue_error2; } book_issue_input_error3: printf("\n Press 0 to return to the previous page\n"); scanf("%d",&book_issue_input); if(book_issue_input==0) { goto administration_page_main; } else(book_issue_input!=0); { printf("\n\t\t\t\t\t ERROR!!! INVALID INPUT"); goto book_issue_input_error3; } } default: { printf("\n ERROR!!! INVALID INPUT"); goto book_issue_error1; } } } case 0: { goto home; } default: { printf("\n ERROR!!! INVALID INPUT\n"); goto administraion_page_main_error; } } } break; } case 2: { int customer_login_cont,book_count_record,book_count,input_login_portal,pass_match_count; int true_or_false=0; customer_portal: //label to return // printf("\n\t\t\t\t\t\t\t\tCUSTOMER LOGIN PAGE\n\t\t\t\t\t\t\tlogin with your username and password\n\n\n Note: case sensitive"); printf("\n\t\t\t\t\t Username: "); scanf("%s",&customer_username); printf("\t\t\t\t\t Password: "); scanf("%s",&customer_pass); pass_match_count=0; while(pass_match_count<=variable_for_signup_counter_loop) { match_pass_customer=strcmp(customer_pass,m[pass_match_count].new_signup_password_array); match_username_customer=strcmp(customer_username,m[pass_match_count].new_signup_username_array); if (match_pass_customer ==0 &&match_username_customer==0) { true_or_false=1; break; } else{ pass_match_count++; } } if(true_or_false==1) //se if the password and the username is correct or not// { // code for customer portal// // add the ampersand in the next printf to print the name of the user// customer_portal_welcome_page: printf("\n\n\n WELCOME !!!"); printf(" \n\n Issued books Press 1"); printf(" \n Book Search Press 2"); printf(" \n Book Request Portal press 3\n"); printf(" \n\n To return to the home page press 0\n"); scanf("%d",&customer_login_cont); switch(customer_login_cont) { case 1: { book_count_record; printf("\n\t\t\t\t\t\t\t ISSUED BOOKS"); printf("\n\ns.no. \t\t\tName of the book \t\t\t Genre\t\t\t Author's name"); printf("\n--------------------------------------------------------------------------------------------------------------"); for(int books_issued_print_counter=1;books_issued_print_counter<=5;books_issued_print_counter++) { printf("\n %d \t\t\t %s %s\t\t\t %s ",books_issued_print_counter,b[m[pass_match_count].issued_book[books_issued_print_counter]].name,b[m[pass_match_count].issued_book[books_issued_print_counter]].genre,b[m[pass_match_count].issued_book[books_issued_print_counter]].author,m[pass_match_count].issued_book[books_issued_print_counter]); } printf("\n\n\t\t\t\t\t\t\t Press 0 to return to previous page"); scanf("%d",&input_login_portal); if(input_login_portal==0) { goto customer_portal_welcome_page; } else { printf("\n\t\t\t\t\t\tERROR!!! INVALID INPUT"); } } case 2: //book search// { int book_search_option; book_search_portal: printf("\n\n\t\t\t\t\t\tBook Search\n"); printf("\n\t\t Search by the name of: "); printf("\n\t\t\t\t\t\t\t Genre Press 1"); printf("\n\t\t\t\t\t\t\t Author press 2"); printf("\n\t\t\t\t\t\t\t Name of the book Press 3"); printf("\n Enter 0 to return to the previous page\n"); book_search_error: scanf("%d",&book_search_option); switch(book_search_option) { case 0: { goto customer_portal_welcome_page; } case 1: { char genre_name[20]; int genre_count,match_genre_name; int truth_genre_search; printf("\n\n Search The Book By It's Genre"); printf("\n Enter The Genre Of The Book: "); gets(flush); gets(genre_name); for(genre_count=0;genre_count<=15;genre_count++) { match_genre_name=strcmp(genre_name,b[genre_count].genre); if(match_genre_name==0) { printf("\n\t Name: %s",b[genre_count].name); printf("\n\t Author: %s",b[genre_count].author); printf("\n\t Genre: %s",b[genre_count].genre); printf("\n"); } if(match_genre_name !=0 && genre_count==15) { printf("book not found"); goto book_search_portal; } } goto book_search_portal; } case 2: { char name_name[20]; int name_count,match_name_name; int truth_name_search; printf("\n\n Search The Book By It's Name"); printf("\n Enter The Name Of The Book: "); gets(flush); gets(name_name); for(name_count=0;name_count<=15;name_count++) { match_name_name=strcmp(name_name,b[name_count].name); if(match_name_name==0) { printf("\n\t Name: %s",b[name_count].name); printf("\n\t Author: %s",b[name_count].author); printf("\n\t Genre: %s",b[name_count].genre); printf("\n"); } if(match_name_name !=0 && name_count==15) { printf(" Sorry!!! book not found"); goto book_search_portal; } } goto book_search_portal; } case 3: { char author_name[20]; int author_count,match_author_name; int truth_author_search; printf("\n\n Search The Book By It's Author"); printf("\n Enter The Author Of The Book: "); gets(flush); gets(author_name); for(author_count=0;author_count<=15;author_count++) { match_author_name=strcmp(author_name,b[author_count].author); if(match_author_name==0 ) { printf("\n\t Name: %s",b[author_count].name); printf("\n\t Author: %s",b[author_count].author); printf("\n\t Genre: %s",b[author_count].genre); printf("\n"); } if(match_author_name!=0 && author_count==15) { printf("book not found"); goto book_search_portal; } } goto book_search_portal; } default: { printf(" ERROR!!! INVALID INPUT"); goto book_search_error; } } } case 3: //book request// { int input_login_portal_from_bookrequest; requested_book_count++; printf(" BOOK REQUEST\n\n"); printf("Enter the name of the book: "); scanf("%s",&requested_book_name[requested_book_count]); printf("\nEnter the name if the author: "); scanf("%s",&requested_book_author[requested_book_count]); printf("\n\n\t\t\t\t\t\t\t\t\t\t\t Press 0 to return to previous page" ); scanf("%d",&input_login_portal_from_bookrequest); if(input_login_portal_from_bookrequest==0) { goto customer_portal_welcome_page; } else { printf("\n\t\t\t\t\t\tERROR!!! INVALID INPUT"); } } case 0: { goto home; } default: { printf("\t\t\t ERROR \t\t\t\n \t\tPlease enter a valid choice"); goto customer_portal_welcome_page; } } } else{ printf(" INCORRECT USERNAME OR PASSWOR\n"); goto customer_portal; } } case 0: { goto home; } } } case 2: //rules of the libray// { int key; printf("\t\t\t\t\t\t\t General Rules \t\t\t\n\n"); printf(" 1.Smoking, eating, sleeping and talking loudly are strictly prohibited in the library\n 2.Mobiles should be kept on silent\n 3.Library membership card is non-transferable.\n 4.Strict silence, decorum and discipline must be maintained in the library.\n 5. No library material can be taken out of the library without permission\n 6.Readers should not mark, underline, dog-ear, write, tear pages or otherwise damage the library documents.\n 7. Replacing the books on shelves is not encouraged as it may get misplaced.\n 8. Any one who violates the rules and regulations of the library would be liable to lose the privilege of library membership and may be debarred from using the library facilities."); printf("\n\n\n\t\t\t\t\t\tPress 0 to return to the home page\n"); scan_input: //label// scanf("%d",&key); //to input the return statement// switch(key) { case 0: goto home; } { printf("\t\t\t ERROR\n \t\t INVALID INPUT"); goto scan_input; } } case 3: //new member sign up// { int confirm,compare,length,quit,random; char pass[15]; char re_pass[15]; char halfname[25]; char copydob[10]; char copyhalfname[25]; signup: variable_for_customer_details++; printf("\t\t\t\t\t\t\tNew Member Sign Up\n"); printf("Please fill the undergiven details\n\n"); gets(flush); printf("Full Name: "); gets(name[variable_for_customer_details]); printf("Date of Birth(dd/mm/yyyy): "); gets(dob[variable_for_customer_details]); printf("Address: "); gets(address[variable_for_customer_details]); password: printf("\ncreate password: "); gets(pass); printf("re-enter your password: "); gets(re_pass); compare=strcmp(pass,re_pass); length=strlen(pass); if(compare==0) //checking if the 2 passwords entered are same or not and warning if the password is too weak// { if(length<9) { printf("\n\t\t\t\t\tPASSWORD ENTERED IS TOO WEAK!!\n\t\t\tPLEASE ENTER A PASSWORD OF ATLEAST 9 CHARACTERS"); goto password; } else { goto endstep; } } else { printf("\n\t\t\t ERROR\n \t\t Password entered does not match\n"); goto password; } endstep: printf("\t\t\t\t\t\tConfirm And Continue\t press 1\n\t\t\t\t\t\tReset Choices\t\t press 2\n\t\t\t NOTE: If you continue then you wont be able to change the details again\n"); printf("\t\t\t\t\t\t press 0 to return to the home page\n"); scanf("%d",&confirm); strcpy(copydob,dob[variable_for_customer_details]); strncpy(halfname,name[variable_for_customer_details],3); strcpy(copyhalfname,halfname); strcat(copyhalfname, copydob); switch(confirm) { case 1: { printf("%s\n",copydob); printf("congrats your account has been successfully made your ID number is %s",copyhalfname); variable_for_signup_counter_loop++; strcpy( m[variable_for_signup_counter_loop].new_signup_username_array,copyhalfname); strcpy(m[variable_for_signup_counter_loop].new_signup_password_array,re_pass); goto home; break; //enter the name and the dob in the username after the string is created// } case 2: { goto signup; break; } case 0: { goto home; } default: { printf("\t\t\t ERROR \t\t\t\t\n \t\tPLEASE ENTER A VALID CHOICE "); printf("\t\t\t\t\t\t press 0 to return to the home page\n"); break; } } } case 4: //lost and found // { char lost_items[20][500]; printf("\t\t\t\t\t\t\tLost and Found\n\n"); // print with string..... user will input in lost items and it should be visible on the lost items list // int items_input; int sno_count; int items_input2; printf("List of lost items \n"); for (sno_count=1;sno_count<=items_count;sno_count++) { if(sno_count==0 && items_count==0) { printf("\t\t\t\t\t\t\n No lost item reported yet"); } else { printf(" \n %d. %s",sno_count,lost_items[sno_count]); } } printf("\n\n\t\t\t\t\tFound a lost item? Report here.\t\t press1\n"); printf("\t\t\t\t\t\t\n Press 0 to return to the home page\n"); lost_and_found_error: scanf("%d",&items_input); switch(items_input) { case 1: { printf("\n\t\t\t\t\t\tReport lost item\n"); printf("enter here: "); items_count++; gets(flush); gets(lost_items[items_count]); lost_and_found_error2: printf("\n\n\t\t\t\t\t\t\t\t\t press 0 to return to the home page\n"); scanf("%d",&items_input2); if(items_input2==0) { goto home; } else { printf("ERROR!!! PLEASE ENTER A VALID CHOICE "); goto lost_and_found_error2; } } case 0: { goto home; } default: { printf("ERROR!!! PLEASE ENTER A VALID CHOICE "); goto lost_and_found_error; } } } case 5: // about the program { printf("\t\t\t\t\t\t\t About\n"); int input_number; printf(" \n\t\t\t\t\t Nischal Sharma"); goto home; } } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue