#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
void replace(char s1[], char s2[], int index)
{
char temp[100];/*定义一个中转的字符数组*/
memset(temp, 0, 100);
strncpy(temp, s1, index - 1);/*将str1中前index个字符拷贝到temp中*/
temp[index] = '\0';
strcat(temp, s2);
strcpy(s1, temp);
}
int main()
{
/*字符串替换*/
/*功能:将“today is Monday”替换为“today is Friday”*/
char str1[100] = "today is Monday";
char str2[100] = "Friday";
int index = 10; /*开始替换的位置*/
replace(str1, str2, index);
puts(str1);
return 0;
}