Menu driven program for simple string operation in c



                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.






#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
int
main()
{
int n;
char str1[20],str2[20];
clrscr();
gotoxy(31,1);
printf("String Menu");
gotoxy(26,3);
printf("http:\\techaravind.blogsopt.com");
gotoxy(1,5);
while(1)
{
printf("\n 1)Length of the string
\n2)concadination of the string
\n3)substring\n
4)reversal of string
\n5)exit");
printf("\n Enter your choice:");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter the string");
gets(str1);
printf("stringlength is:%d",strlen(str1));
break;

case 2:
printf("\nEnter the string1");
gets(str1);
printf("\nEnter the string2");
gets(str2);
printf("\nThe conctinated sting is: %s",strcat(str1,str2));
break;

case 3:
printf("\nEnter the string1");
gets(str1);
printf("\nEnter the string2");
gets(str2);
printf("the substing is:%s",strstr(str1,str2));
break;

case 4:
printf("\nEnter the string1");
gets(str1);
printf("\n The reverce of the strint is");
break;

case 5:
exit(0);
}
}




0 comments:

Post a Comment

 
Etutos © 2010-2011