Create Menu Program in C

Hello, Dear student today we learn  Creating Menu Program in C using scanf_s & gets_s Function. Here also another program that we make using only gets(); Function

Menu program in C using scanf_s & get_s Function

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <math.h>

#define NUM_STRINGS 10 
#define STRING_SIZE 65
#define MAX_SIZE 8
#define MAX_ROW MAX_SIZE+1

int get_num(int lowest, int largest) {
int num;
scanf("%d", &num);
if (num > largest || num < lowest) {
printf("Illegal number. Please re-enter a number:\n");
return get_num(lowest, largest);
}
else {
return num;
}
}

int printMenue() {
printf("Please choose an option:\n");
printf("1. Add String\n");
printf("2. Remove Duplicates\n");
printf("3. Narrow a String\n");
printf("4. Maximum Subset\n");
printf("5. Mini Scrabble\n");
printf("6. Crossword Puzzle\n");
printf("7. Print Strings\n");
printf("8. Exit\n");
return get_num(1, 8);
}

void strPrint(char str[][STRING_SIZE], int numOfStrings ) {
//puts(str);
if (numOfStrings > 9) return;
else {
//char c;
//c = str[numOfStrings];
if (strcmp(str[numOfStrings],"")==0){ //c == "") {
strPrint(str, numOfStrings + 1);
}
else {
printf("%d) ", numOfStrings);
printf("%s\n", str[numOfStrings]);
strPrint(str, numOfStrings + 1);
}
}
}

void main() {

static int first = 0;
static char firstPrint[] = "Hello and welcome!";
if (!first) {
puts(firstPrint);
first = 1;
}
char strings[NUM_STRINGS][STRING_SIZE] =
{ { "" }, { "" }, { "" }, { "" }, { "" }, { "" }, { "" }, { "" }, { "" }, { "" } };
int op, slot;
char ignorValue;
do
{
op = printMenue();
char str[65];
switch (op) {
case 1:
printf("Please choose a string slot:\n");
scanf("%d", &slot);
printf("Please enter a string:\n");
ignorValue = getchar();
gets(strings[slot]);
// strcpy(strings[slot],str);
break;
case 2:
printf("option 2\n");

break;
case 3:
printf("option 3");

break;
case 4:
printf("option 4");

break;
case 5:
printf("option 5");

break;
case 6:
printf("option 6");

break;
case 7:
strPrint(strings, 0);

break;
case 8:
return;
}
}
while(op!=8);
}
Don’t worry about the Output of the Working Menu Program in C

Working Menu Program in C using gets();

This is the Second way to making the same program in C but using instead of gets_s only gets(); Function.

Run 2
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <math.h>

#define NUM_STRINGS 10
#define STRING_SIZE 65
#define MAX_SIZE 8
#define MAX_ROW MAX_SIZE+1

int get_num(int lowest, int largest) {
int num;
scanf("%d", &num);
if (num > largest || num < lowest) {
printf("Illegal number. Please re-enter a number:\n");
return get_num(lowest, largest);
}
else {
return num;
}
}

int printMenue() {
printf("Please choose an option:\n");
printf("1. Add String\n");
printf("2. Remove Duplicates\n");
printf("3. Narrow a String\n");
printf("4. Maximum Subset\n");
printf("5. Mini Scrabble\n");
printf("6. Crossword Puzzle\n");
printf("7. Print Strings\n");
printf("8. Exit\n");
return get_num(1, 8);
}

void strPrint(char str[][STRING_SIZE], int numOfStrings ) {
//puts(str);
if (numOfStrings > 9) return;
else {
//char c;
//c = str[numOfStrings];
if (strcmp(str[numOfStrings],"")==0){ //c == "") {
strPrint(str, numOfStrings + 1);
}
else {
printf("%d) ", numOfStrings);
printf("%s\n", str[numOfStrings]);
strPrint(str, numOfStrings + 1);
}
}
}

void main() {

static int first = 0;
static char firstPrint[] = "Hello and welcome!";
if (!first) {
puts(firstPrint);
first = 1;
}
char strings[NUM_STRINGS][STRING_SIZE] =
{ { "" }, { "" }, { "" }, { "" }, { "" }, { "" }, { "" }, { "" }, { "" }, { "" } };
int op, slot;
char ignorValue;
printOptions : // label for goto
op = printMenue();
char str[65];
switch (op) {
case 1:

printf("Please choose a string slot:\n");
scanf("%d", &slot);
printf("Please enter a string:\n");
ignorValue = getchar();
gets(strings[slot]);
goto printOptions; // goto label printOptions
break;
case 2:
printf("option 2\n");

break;
case 3:
printf("option 3");

break;
case 4:
printf("option 4");

break;
case 5:
printf("option 5");

break;
case 6:
printf("option 6");

break;

case 7:

strPrint(strings, 0);
goto printOptions; // goto label printOptions
break;

case 8:
return;
}

}

Menu making Program in C

1st Output of the Create Menu Program in C using gets

Create Menu Program in C
Create Menu Program in C
Actually in the Create Menu Program in C using Sanf_s and gets(); there is no differences, both are working Same.

END

Menu programming in C

Menu program Using Array and Function (clickHere)

Note:- Maybe sometime above code doesn’t get user-friendly output, in codeblock ‘or’ any other EDITOR, All of C & C++ program tested in DOS compiler Turbo C.

Also Read

Types of functions in C READ HERE

I hope you will understand better if you study at M.U, in the exam of M.U you know how important this “Create Menu Program in C. So please don’t forget to give your valuable feedback. Go in the comment section and Give us some feedback about it. Create Menu Program in C or My website.

Our team check your every Comment per day Because your one feedback helps us in growing Thesmolt

I request you if you have any doubt or question regarding our site, then please don’t hesitate, We always waiting for your Suggestion.

Note:- If you want to Download This article’s in PDF form, then simply go (Top or Bottom of) Right corner and click on the PRINT icon, and it’s saved as a PDF of Create Menu Program in C

C program to Display Current Date and Time

For further questions, you can contact us Via mail [email protected]  otherwise, Our Help Page and Contact us Page, which is included below. I hope I’ll able to say all the possible ways to reach us. Or Download My Android Application Below Download Button.

thesmolt App

Leave a Reply

x