Easy String Operations in C Language
Write a Easy String Operations program in C to carry out String operations on strings utilizing library capabilities
- Concatenate a string S3 to string S2.
- Copy a string S3 to a different string S2.
- Discover the size of a given string
- Examine two strings S2 and S3.
Easy String Operations Code
1 |
#embrace <stdio.h><br/>#embrace <string.h><br/>#embrace<conio.h><br/>#outline MAXLEN 120<br/>void principal()<br/>{<br/>char string1[MAXLEN], string2[MAXLEN]; <br/>char consequence[MAXLEN]; <br/>int selection,exercise;<br/>int comparability;<br/>clrscr();<br/>whereas(1)<br/>{<br/><br/>printf(“Enter your selection :n”);<br/><br/>printf(“1. Enter the stringsn”);<br/>printf(“2. To concatenate a string S2 to string S1n”);<br/>printf(“3. To seek out the size of a given stringn”);<br/>printf(“4. To check two strings S1 and S2.n”);<br/>printf(“5. To repeat a string S2 to a different string S1.n”);<br/>printf(“6. Show S1 and S2.n”);<br/>printf(“0. Exit nn”);<br/>printf(“Your Alternative: “);<br/><br/>scanf(“%d”, &selection);<br/><br/>change(selection)<br/>{<br/><br/>case 1:<br/><br/>printf(“Please enter first string (most size %d) n”, MAXLEN – 1);<br/>flushall();<br/>will get(string1);<br/><br/>printf(“Please enter second string (most size %d) n”, MAXLEN – 1);<br/>flushall();<br/>will get(string2);<br/>break;<br/>case 2:<br/>strcat(string1, string2);<br/><br/>printf(“S1 now could be :npercentsn”, string1);<br/><br/>break;<br/>case 3:<br/>printf(“Please choose a string to search out size ofn”);<br/><br/>printf(“1. S1n”);<br/>printf(“2. S2n”);<br/>printf(“3. New stringn”);<br/><br/>scanf(“%d”, &exercise);<br/><br/>change(exercise)<br/>{<br/>case 1:<br/>printf(“The size is %dn”, strlen(string1));<br/><br/>break;<br/>case 2:<br/>printf(“The size is %dn”, strlen(string2));<br/><br/>break;<br/>case 3:<br/>printf(“Please enter new string (most size %d) n”, MAXLEN – 1);<br/>scanf(“%s”,consequence);<br/>printf(“The size is %dn”, strlen(consequence));<br/><br/>break;<br/>}<br/>break;<br/>case 4:<br/>comparability = strcmp(string1,string2);<br/><br/>if(comparability < 0)<br/>{<br/>printf(“S1 is lexicographically equal to S2n”);<br/><br/>}<br/>else if (comparability < 0)<br/>{<br/>printf(“S1 is lexicographically smaller than S2n”);<br/><br/>}<br/>else<br/>{<br/>printf(“S1 is lexicographically higher than S2n”);<br/><br/>}<br/>break;<br/>case 5:<br/>strcpy(string1, string2);<br/><br/>printf(“S1 is now :npercentsn”, string1);<br/><br/>break;<br/>case 6:<br/>printf(“S1 is now :npercentsn”, string1);<br/>printf(“S2 is now :npercentsn”, string2);<br/>break;<br/>case 0: exit();<br/><br/>}<br/>printf(“nn”);<br/>}<br/>} |
Supply projectgeek.com