Monday, 8 December 2014

replace str2 in str1 at particular index value
#include<stdio.h>
#include<string.h>
char* mystrcat(char*,char*,int);
//int mystrcmp(char*,char*);
main()
{
char str1[50],str2[50];
int n;
printf("enter string1\n");
scanf("%[^\n]s",str1);
printf("enter string2\n");
scanf(" %[^\n]s",str2);
printf("enter index value\n");
scanf("%d",&n);
mystrcat(str1,str2,n);
printf("str1=%s str2=%s\n",str1,str2);
}
char* mystrcat(char* s1,char* s2,int n)
{
memmove(s1+n-1+strlen(s2),s1+n-1,strlen(s1+n-1));
memcpy(s1+strlen(s2)-1,s2,strlen(s2));
//strcat(s1+3,s2);
//printf("s1=%s s2=%s\n",s1,s2);
return(s1,s2);
}
OutPut:
madan@madan-Lenovo-G570:~/madan$ cc array11.c
madan@madan-Lenovo-G570:~/madan$ ./a.out
enter string1
welcome
enter string2
com
enter index value
2
str1=wecomlcome@ str2=com