[小菜举手]编译的时候,为什么会响铃?---串的问题
win2003+vc6.0,编译时,产生如同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);
}
[解决办法]
你是说那声音?仔细听听
编译完全正确,有报错,printf( "\a ");三者都不同