VC6.0+win2003,编译时,产生如同printf("\a")的效果,是因为有什么错误吗?
code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct
{
char *ch;
int length;
}HString;
void HStrInit(HString *s)
{
s->ch=NULL;
s->length=0;
}
void StrAssign(HString *s,char *ts)
{
int len=strlen(ts);
if(len)
{
s->ch=(char *)malloc(len+1);//'\0'
strcpy(s->ch,ts);
s->length=len;
}
}
void Concat(HString *s,HString *d)
{
int n=0,len=d->length;
if(!len)
{
printf("ERROR d->length\n");
return;
}
s->ch=(char *)realloc(s->ch,s->length+len);
for(n=s->length;n<s->length+len;n++)
s->ch[n]=d->ch[n-s->length];
s->length+=d->length;
}
void main()
{
HString s,d;
HStrInit(&s);
HStrInit(&d);
char *t1="for test!";
char *t2="128";
StrAssign(&s,t1);
StrAssign(&d,t2);
//StrCpy(&d,&s);
//InsertStr(&s,9,&d);
Concat(&s,&d);
printf("%s %d\n",s.ch,s.length);
}