17.c

来自「数据结构练习共18道。」· C语言 代码 · 共 37 行

C
37
字号
#include "stdio.h"
#include "string.h"

void main(){
	char source[200],sub[100],destination[100];
	int slen,dlen,pos,i,temp;
	printf("Input the source string:");
	gets(source);
	printf("\nInput the destination string:");
	gets(destination);

	slen=strlen(source);
	dlen=strlen(destination);

	printf("\nInput the pos you want to insert:");
	scanf("%d",&pos);
	
	if (pos>slen||pos<1)
	{
		printf("Position Error!!");
		return;
	}
	else{
		temp=pos-1;
		for(i=0;i<=slen-pos+1;i++)
			sub[i]=source[temp++];
		
		puts(sub);
		source[pos-1]='\0';
		strcat(source,destination);
		strcat(source,sub);

	}
	puts(source);
	printf("\n");

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?