Write a C Program that does the following:
1. Declares a C-String called ‘m1’ and initializes it with the text “Programming is great fun!”.
2. Uses C-function puts() to print this string.
3. Asks the user to enter a string named ‘m2’ (Hint: Use gets() function for this.)
4. Concatenates the two strings and stores the result in ‘m3’.
For example, if the user enters m2 as “Not Really!”, m3 should be “Programming is great fun! Not really!”
5. Inserts the user entered array (m2) into m1 after “Programming is ...”
For the above example, the resultant String would become “Programming is Not really! great fun!”
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
int main()
{
char m1[]={"Programming is great fun "};
puts(m1);
char m2[50];
printf("\nEnter another string : ");
gets(m2);
strcat(m1,m2);
char m3[]="";
strcat(m3,m1);
printf("Concatenated string : ");
puts(m3);
printf("User entered string in original string : ");
puts(m1);
}
Comments
Leave a comment