TC 中定义字符指针

来源:百度知道 编辑:UC知道 时间:2024/05/25 05:36:18
写了个程序
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
void insert();
main()
{
char s[20],s1[20];
int n;
scanf("%s%s%d",s,s1,&n);
insert(s,s1,n);
printf("%s",s);
system("pause");
}
void insert(char s[],char s1[],int n)
{
int a;
a=strlen(s1);
char *x=s+n+a,*p=s+n;
while(*(p-1))*x++=*p++;
p=s+n;
while(*s1)*p++=*s1++;
}
在TC中编译时说那些指针变量没定义,这是什么意思啊?
是的
改了,还是有问题啊

你的目的是插入1个字符串么```?
char *x=s+n+a,*p=s+n;着里定义的有问题```声明
a=strlen(s1);在这个后面了``` a=strlen(s1);把这个移到后面`

===================================
像这样``int a;
char *x;
char p;
a=strlen(s1);
x=s+n+a;
p=s+n;

编译是没问题的``你算发有问题``
我看下``==

#include<stdio.h>
#define MAX 100
void insert(char a[MAX],char b[MAX],int i)
{
int alen=0,blen=0,k;
while(a[alen]!='\0')
{alen++;}/*获取数组a的长度*/
while(b[blen]!='\0')
{blen++;}/*获取数组b的长度*/

for(k=alen+blen-1;k>=blen+i-1;k--)
a[k]=a[k-blen];
for(k=i-1;k<i+blen-1;k++)
a[k]=b[k-i+1];
a[alen+blen]='\0';
}

void main()
{
int i,n;
char a[MAX],b[MAX];
printf("please input the 1st string:");
gets(a);
printf("please input the 2nd string:");
gets(b);
printf("please input the number:&qu