How to write a menu driven program in C
1: calculate the length of string
2: copy one string into another
3: compare two string
4: concatenate of two string
Solution:
/* write a menu driven program
1: calculate the length of string
2: copy one string into another
3: compare two string
4: concatenate of two string */
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[30],b[30];
int ch,n;
clrscr();
printf("\n1:length of string:");
printf("\n2:copy string");
printf("\n3:compare string");
printf("\n4:concatenate two string");
printf("\nenter your choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("\nenter the string:");
flushall();
gets(a);
n=strlen(a);
printf("\nthe lenght of string is :%d",n);
break;
case 2:printf("\nenter the firs string :");
flushall();
scanf("%s",&a);
strcpy(b,a);
printf("the copied string is :%s",b);
break;
case 3:printf("\nenter first string :");
flushall();
scanf("%s",&a);
printf("\nenter second string :");
flushall();
scanf("%s",&b);
if(strcmp(a,b)>0)
printf("\nstring a is greater");
else
printf("\nstring b is greater");
break;
case 4:printf("\nenter first string :");
flushall();
scanf("%s",&a);
printf("\nenter second string :");
flushall();
scanf("%s",&b);
strcat(a,b);
printf("\nthe source string is :%s",b);
printf("\nthe target string is : %s",a);
break;
}
getch();
}
/*
1:length of string:
2:copy string
3:compare string
4:concatenate two string
enter your choice :1
enter the string:peer
the lenght of string is :4
1:length of string:
2:copy string
3:compare string
4:concatenate two string
enter your choice :2
enter the firs string :peersaab
the copied string is :peersaab
1:length of string:
2:copy string
3:compare string
4:concatenate two string
enter your choice :3
enter first string :peersaab
enter second string :nadaf
string a is greater
1:length of string:
2:copy string
3:compare string
4:concatenate two string
enter your choice :4
enter first string :peer
enter second string :saab
the source string is :saab
the target string is : peersaab
*/
Learn More :
Concatenate
Menu Driven Program
String
- Write a c program to check given string is palindrome number or not.
- C Program to Convert Text String to Binary
- C Program String - Alphabet Count Example
- C Program String Example
- C Program String Count Example
- C Program String Example
- C Program to Print a String Without Use Semicolon.
- C Program To Find Length Of A String Including Blank Spaces, Tabs, And Other Special Characters
- C Program To Find Length Of String And Concatenate Two Strings
- C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not
- C Program To Print String In Formatted Output Form
- C Program To Reverse The String Using Pointer
- C Program Concatenating Two Strings Into A Third System
- C Program Date from string DDDD-DD-DD
- BUILDS A STRING FROM THE LSB BITS OF EACH PIXEL
- C Program Finds Sub-String Search in String
- C Program to concatenate two strings without using string functions
- C Program to Count Vowels, Consonants and Spaces in a string
- C Program to convert a string to upper case
- C Program Performs a search and replace for a specified target and replacement string
- C Program Anagrams
- C Program to find string length without library function
- C Program to Check Given String is Palindrome or Not
- C Program to Converts a Number to a String.
- Design a C function that shortens a string to 8 characters
Compare
Length
- C Program To Find Length Of A String Including Blank Spaces, Tabs, And Other Special Characters
- C Program To Find Length Of String And Concatenate Two Strings
- C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not
- C Program to calculate Area, Perimeter of Rectangle; Area, Circumference of Circle.
- C Program to find string length without library function
- C Program that prompts the user to input a string, (whitespaces allowed)
Copy
- COPY DATA FROM ONE FILE TO ANOTHER FILE USING C PROGRAM
- C Program To Copy One Character Array Into Another
- C Program/Code to Copies a BMP piece by piece
- Make a copy of file given in argv[1] to file given in argv[2]
- C Program to copy a file to another file
- A small I/O bound program to copy N bytes from an input file to an output file.
- C Program to Create a copy of an image
- C Program Copies a BMP piece by piece
Calculate
- C Programm zur Berechnung von Umfang und Flächeninhalt verschiedener geomatrischer Figuren
- Napisać funkcję obliczającą funkcję geometryczną w tablicy NxM elementowej z elementów o wartościach parzystych znajdujących się pod główną i ponad przeciwną przekątną.
- C Program to Calculate GCD using recursion
- C Program To Calculate First Numbers Using Recursion
- C Program to Calculation of One Number Raised to Another
- C Program to calculate TT and Recharge Amount
- C Program to Calculate 2 numbers with 1 operation
- Un-sortiertes Array and Sortiertes Array
- C Program Calculation of Simple Interest
- C Program to Calculation of Total and Percentage
- C Program for calculation of Gross Salary
- C Program to calculate Area, Perimeter of Rectangle; Area, Circumference of Circle.
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- C Program for statistically calculating pi using a specific scheduling policy.
- C Program that prompts the user to input a string, (whitespaces allowed)
- C Program Number of Judge and Score From Each Judge
- C Program to Calculate the mathematical expression for the first n numbers
- C Program to Calculate the price of movie tickets
- C Program to calculate sum of two m*n matrices & store the result in 3 matrix
- C Program to calculate the sum of elements of upper triangle of a n*n matrix using DMA
- C Program to accept n numbers from user store these numbers into an array & calculate average of n numbers
- Calculate sum of element of upper triangle of m*n matrix by using dynamic memory allocation
- Calculate sum of non-diagonal element in m*n matrix C Program
- Accept n number from user, store these number into an array and calculate the average of n number
- Calculate sum of element of lower triangle of m*n matrix by using dynamic memory allocation
Two
- Write a c program to find out H.C.F. of two numbers.
- Write a C program to find maximum or equal between two numbers ?
- ADDITION OF TWO MATRICES USING C PROGRAM
- C Program To Find Product Of Two No Using MACRO
- C Program To Swap Two Numbers Without Using Third Variable
- C Program Concatenating Two Strings Into A Third System
- C Program to concatenate two strings without using string functions
- C Program to Interchanging Two Numbers
- C Program produsul scalar a doi vectori .
- C Program The dot product of two vectors
- C Program to two timing functions to measure process time
- C Program to calculate sum of two m*n matrices & store the result in 3 matrix
- C Program to swap the values of two variables by using call by reference
- Find the union and intersection of two sets of integer store it in two array C Program
- C Program To Multiply Two Polynomials
- Create Two Singly Linked List Perform Differences Display It C Program
- C Program to Input Student Details into a File For Two Subjects
- Adding two polynomial functions C Program Using Structure
- Program to Add Two Polynomials Using Linked List C Program
- Menu Driven Program to Read Two Integers Find Sum, Difference and Product C Program
- Input Two Numbers and Print Greater Number C Program