这是源码
#include<stdio.h>
#include<string.h>
insert(char *s,char *p,int i);
int main(void)
{
char*strin, str[80]="hell world!";
int i;
strin="big";
printf("please input the positon you want to insert:");
scanf("%d",&i);
insert(str,strin,i);
printf("\n%s\n",str);
getchar();
}
insert(char s,char q,int n)
{
int i=0;
char *s1=s,*str, strcp[80];
str=strcp;
for(i=0; *s1!='\0';i++)
{
if(i==n-1)
{
for(; *q!='\0';)
{
strcp[i]=*q;
q++;
i++;
}
}
strcp[i]= *s1;
s++;
}
strcp[1]='\0';
strcpy(s,strcp);
}
#include <stdio.h>
#include<string.h>
insert(char *s,char *q,int i);
int main(void)
{
char *strin, str[80]="Hello world!";
int i;
strin = "big ";
printf("Please input the positon you want to insert:");
scanf("%d", &i); /*输入插入位置*/
insert(str, strin, i); /*在指定位置插入*/
printf("\n%s\n", str); /*输出插入后的字符串*/
getch();
}
insert(char *s, char *q, int n)
{
int i = 0;
char *s1=s,*str, strcp[80];
str = strcp; /*把数组首地址赋给指针变量*/
for(i=0;*s1!='\0';i++)
{
if (i == n - 1)
{
for (; *q != '\0';) /*循环插入字符串*/
{
strcp[i] = *q; /*插入字符*/
q++;
i++;
}
}
strcp[i] = *s1;
s1++;
}
strcp[i] = '\0';
strcpy(s,strcp);
}
是不是缺少什么组件 或者我的c++系统出问题了 刚开始安装的时候和书上的步骤不太一样 但是 后来安上了
#include <stdio.h>
#include<string.h>
void insert(char *s, char *q, int n);
int main(void)
{
char *strin, str[80]="Hello world!";
int i;
strin = "big ";
printf("Please input the positon you want to insert:");
scanf("%d", &i); /*输入插入位置*/
insert(str, strin, i); /*在指定位置插入*/
printf("\n%s\n", str); /*输出插入后的字符串*/
getchar();
}
void insert(char *s, char *q, int n)
{
int i = 0;
char *s1=s,*str, strcp[80];
str = strcp; /*把数组首地址赋给指针变量*/
for(i=0;*s1!='\0';i++)
{
if (i == n - 1)
{
for (; *q != '\0';) /*循环插入字符串*/
{
strcp[i] = *q; /*插入字符*/
q++;
i++;
}
}
strcp[i] = *s1;
s1++;
}
strcp[i] = '\0';
strcpy(s,strcp);
}