当前位置: 代码迷 >> C语言 >> [求助]串的插入怎么运行不了啊
  详细解决方案

[求助]串的插入怎么运行不了啊

热度:323   发布时间:2006-12-19 22:48:09.0
[求助]串的插入怎么运行不了啊

#include "stdio.h"
#define MAX 50
typedef struct {
char ch[MAX];
int len;
}SString;

void StrInsert(SString *s,int pos,SString *t)
{
int i;
for(i=s->len+t->len-1;i>=t->len+pos;i--)
s->ch[i]=s->ch[i-t->len];
for(i=0;i<t->len;i++)
s->ch[i+pos]=t->ch[i];
s->len=s->len+t->len;
}

void main()
{
SString *s,*t;

int k,i;
char a[]="abcdef";
char b[]="UVW";
s=a;
t=b;
printf("input k:");
scanf("%d",&k);
StrInsert(s,k,t);
for(i=0;i<=MAX;i++)
printf("%c ",s->ch[i]);
}


搜索更多相关的解决方案: len  int  SString  pos  

----------------解决方案--------------------------------------------------------
实在是搞不清楚你的函数参数是怎么定义的,把哪个超哪个里面插写清楚撒!
用个strSource和strDest;
annot convert from 'char [7]' to 'SString *'
返回类型不匹配,在函数里面return一下试
----------------解决方案--------------------------------------------------------

数据定义 问题大
自己去看看结构体怎么定义的


----------------解决方案--------------------------------------------------------

#include "stdio.h"
#define MAX 50
typedef struct {
char ch[MAX];
int len;
}SString;

void StrInsert(SString *s,int pos,SString *t)
{
int i;
for(i=s->len+t->len-1;i>=t->len+pos;i--)
s->ch[i]=s->ch[i-t->len];
for(i=0;i<t->len;i++)
s->ch[i+pos]=t->ch[i];
s->len=s->len+t->len;
}

void main()
{
SString *s,*t;

int k,i;
char a[]="abcdef";
char b[]="UVW";
s=a;
t=b;
printf("input k:");
scanf("%d",&k);
StrInsert(s,k,t);
for(i=0;i<=MAX;i++)
printf("%c ",s->ch[i]);
}


----------------解决方案--------------------------------------------------------

#include "stdio.h"
#define MAX 50
typedef struct {
char ch[MAX];
int len;
}SString;

void StrInsert(SString *s,int pos,SString *t)
{
int i;
for(i=s->len+t->len;i>=t->len+pos;i--)
s->ch[i]=s->ch[i-t->len];
for(i=0;i<t->len;i++)
s->ch[i+pos]=t->ch[i];
s->len=s->len+t->len;
}

void main()
{
SString *s,*t,c,d;

int k,i;
char a[]="abcdef";
char b[]="UVW";
s=&c;
t=&d;
strcpy(s->ch,a);
strcpy(t->ch,b);
s->len=strlen(a);
t->len=strlen(b);
printf("input k:");
scanf("%d",&k);
StrInsert(s,k,t);

printf("%s",s->ch);
}

[此贴子已经被作者于2006-12-21 1:52:45编辑过]


----------------解决方案--------------------------------------------------------
谢谢了啊,问题已经解决。
----------------解决方案--------------------------------------------------------
  相关解决方案