#include #include //declaring the fuctions I will be needing. void displayList(); void Insert_AppendList(); void obtainList(); void clearList(); //without memset int list[21]; //declaring some global vars, so I can use between funtions. int choice,indexChoice,addedNumber,obtained,i=1; int main() { while (1) //infinite loop to wrap back to the menu. { //making output menu-styled. fprintf(stdout,"\n////////////////////////////////////////////\n// 1.Build\t 2.Display\t3.Insert \n// 4.Append into 5.Obtain from\t6.Clear\n// 7.Quit\n////////////////////////////////////////////\nMatch the list options menu number to the desired list and input HERE: "); scanf("%d",&choice); switch (choice) //switch statement to map menu choice to processes. { case 1: while (list[i-1]!=-1) { if (i>=21) //limit to 20 numbers in index { list[21]=-1; printf("\nYour building list is full.\n"); break; } if (i==1) //give directions first time around { printf("\nEnter numbers until you are done building your list (20 numbers max). When your list is done enter -1 to singnal the end of the list. INPUT FIRST NUMBER: "); } else { printf("Next number: "); // continue prompting numbers } scanf("%d",&list[i]); i++; // go tonext element in array } break; case 2: displayList(); // print out list break; case 3: if(list[1]==0) // assume there is no list if first number is 0 { printf("OOPS! It looks like you don't have a list yet.\n"); break; } printf("Where would you like to insert?(1-20): "); scanf("%d",&indexChoice); indexChoice--; printf("[Enter Number] index%d: ",indexChoice); scanf("%d",&addedNumber); Insert_AppendList(); //use to capture index before break; case 4: if(list[1]==0) { printf("OOPS! It looks like you don't have a list yet.\n"); break; } printf("Where would you like to append?(1-20): "); scanf("%d",&indexChoice); indexChoice++; printf("[Enter Number] index%d: ",indexChoice); scanf("%d",&addedNumber); Insert_AppendList();//used to capture index after break; case 5: if(list[1]==0) { printf("OOPS! It looks like you don't have a list yet.\n"); break; } printf("Which index number to obtain from?(1-20): "); scanf("%d",&indexChoice); obtainList(); displayList(); printf("\nNumber Obtained: %d\n",obtained); //print number obtained with function break; case 6: clearList(); printf("\nLIST CLREARED\n"); break; case 7: printf("\nList's will not be saved, ARE YOU SURE?\n(1.Yes|2.No)\n"); scanf("%d",&indexChoice); if (indexChoice==1) //exit if selected with 1, otherwise continue with loop. exit(0); break; default://The default if none of the menu options are selected. fprintf(stderr,"\nINVALID MENU OPTON, read the menu and try again.\n"); exit(1); break; } } return(0); } void displayList() { i=1; while(list[i]!=-1) { if(list[1]==0) { printf("OOPS! It looks like you don't have a list yet.\n"); break; } else { printf("index%d: %d\n",i,list[i]); //navigate and print array i++; //until end of list marker. } } } void Insert_AppendList() { int holder,holder2; i=indexChoice; if(i<21) { holder=list[i]; list[i]=addedNumber; i++; while(i<21) // Buffers to insert and shift w/o losing data. { holder2=list[i]; list[i]=holder; i++; holder=list[i]; list[i]=holder2; i++; } } else printf("\nYou are limited to 20 index's.\n");//incase try to store past 20 } void obtainList() { obtained=list[indexChoice]; // to obatin and erase. list[indexChoice]=0; } void clearList() { i=1; while(i<=20) { list[i]=0;//set everything to 0. i++; } }