Menu in c programming

In these programs, you will learn how to work the Menu system in c programming menu system, with step by step examples for a menu in c programming using a combination of Array and Function.

Menu driven program in c using Functions

#define COLS 10;
#define ROW 20;
#include <stdio.h>
#include <string.h>
#include <math.h>

void printMenu()

{

printf(“Hello!!!!!!\n”);
printf(“===========\n”);
printf(“Please choose from the menu:\n”);
printf(“Enter – enter matrix\n”);
printf(“Print – print matrix\n”);
printf(“Rotate – rotate matrix\n”);
printf(“Exit – exit the program\n”);

}

void toLower(char str[]) {
for (int i = 0; i < 20; i++) {
if (str[i] >= ‘A’ && str[i] <= ‘Z’) str[i] += 32;
}
}

int getInput(char str[]) { //the new function

// gets_s(str,20);
toLower(str);

scanf(“%s”,str); // try this function if gets_s is not working for u scanf_s(“%s”,str,20); try like this
//toLower(str);

}

int main()
{
char str[20];
int isExit=0;

do
{
printMenu();
getInput(str);

if(strcmp(str,”exit”)==0)
isExit=1;
}
while(isExit!=1) ;

return 0;
}

Menu driven program in c using Array

The user chose from the menu by the first word of the option (print, rotate…) and he can write it with a lowercase letter or uppercase. “to lower” function take the string the user wrote and turns every latter to lowercase. after i have only a lowercase string i need to check what the user chose with the function “getInput”. this function should return a different value for every choice from the menu. if the word given wasn’t from the menu it should “say” it and print the menu again Menu in c programming

Run 2

#define COLS 10;
#define ROW 20;
#include <stdio.h>
#include <string.h>
#include <math.h>
char options[][20]={“enter”,”print”,”rotate”,”exit”};
void printMenu() {

printf(“Hello!!!!!!\n”);
printf(“===========\n”);
printf(“Please choose from the menu:\n”);
printf(“Enter – enter matrix\n”);
printf(“Print – print matrix\n”);
printf(“Rotate – rotate matrix\n”);
printf(“Exit – exit the program\n”);

}

void toLower(char str[]) {
for (int i = 0; i < 20; i++) {
if (str[i] >= ‘A’ && str[i] <= ‘Z’) str[i] += 32;
}
}

int getInput(char str[]) { //the new function

//gets_s(str,20);
//toLower(str);

scanf(“%s”,str); // try this function if gets_s is not working for u scanf_s(“%s”,str,20);
toLower(str);
int i=0;

int index=-1;
for(i=0;i<4;i++){
if(strcmp(options[i],str)==0){
index=i;
break;
// printf(“%s\n”,options[i]);

}
}
return index;
}

int main()
{
char str[20];

int isExit=0;

do
{
printMenu();
switch(getInput(str)){
case 3:
isExit=1;
break;

}

}
while(isExit!=1) ;

return 0;
}

Menu in C programming

Create a menu in c programming

Menu in c programming
Menu in c programming

END

C program to draw a square using graphics (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 “Menu in C programming. So please don’t forget to give your valuable feedback. Go in the comment section and Give us some feedback about it. Menu in C programmingor My website.

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

Creating a menu program in C

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 Menu in C programming

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