Thursday, November 27, 2014

C Program to insert a string into another string

/*.................................................................................................................................
File : rec17.c
Program : Insert a string into another string
Author : 141740
Date : 15/11/2014
......................................................................................................................................*/
#include<stdio.h>
void StrInsert(int N,char S[],char T[]);
main()
{
int n;
char s[30],t[30];
system("clear");
printf("Program to insert a string into another string\n");
printf("Enter first string\n");
scanf("%s",t);
printf("Enter the second string\n");
scanf("%s",s);
printf("After how many letters \n");
scanf("%d",&n);
StrInsert(n,s,t);
}
void StrInsert(int N,char S[],char T[])
{
int i;
i=0;
while(T[i]!='\0'){
S[N]=T[i];
i++;
N++;
}
printf("%s\n",S);
}


OUTPUT 1
Program to insert a string into another string
Enter first string
kkpp
Enter the second string
tt
After how many letters
2
ttkkpp
[141740@localhost ~]$


OUTPUT 2
Program to insert a string into another string
Enter first string
night
Enter the second string
good
After how many letters
4
goodnight
[141740@localhost ~]$

No comments:

Post a Comment