visual studio 中的“Ì”或“\0”为空
'Ì' or '\0' in visual studio is null
我在visual studio中写了一段代码,在算法中似乎是正确的,但是
但不会工作!我不知道我的代码 Ì
(-52) 或 [=13=]
void strcat(char *destin, char *source){
while (*destin != '[=11=]')
destin++;
while (*source != '[=11=]')
{
*destin = *source;
destin++;
source++;
}
*destin = '[=11=]';
}
main(){
char s1[100];
strcat(s1, "salam");
strcat(s1, "hello");
strcat(s1, "ahlan");
strcat(s1, "keifolhal");
printf("%s", s1);
return 0;
}
您忘记在源数组中放置终止零。写入
char s1[100];
s1[0] = '[=10=]';
或
char s1[100] = { '[=11=]' };
或
char s1[100] = "";
或
char s1[100] = { "" };
最后三个声明是等价的。
函数本身可以这样写
char * strcat( char *destin, const char *source )
{
char *p = destin;
while ( *p != '[=14=]' ) p++;
while ( *p++ = *source++ );
return destin;
}
我在visual studio中写了一段代码,在算法中似乎是正确的,但是
但不会工作!我不知道我的代码 Ì
(-52) 或 [=13=]
void strcat(char *destin, char *source){
while (*destin != '[=11=]')
destin++;
while (*source != '[=11=]')
{
*destin = *source;
destin++;
source++;
}
*destin = '[=11=]';
}
main(){
char s1[100];
strcat(s1, "salam");
strcat(s1, "hello");
strcat(s1, "ahlan");
strcat(s1, "keifolhal");
printf("%s", s1);
return 0;
}
您忘记在源数组中放置终止零。写入
char s1[100];
s1[0] = '[=10=]';
或
char s1[100] = { '[=11=]' };
或
char s1[100] = "";
或
char s1[100] = { "" };
最后三个声明是等价的。
函数本身可以这样写
char * strcat( char *destin, const char *source )
{
char *p = destin;
while ( *p != '[=14=]' ) p++;
while ( *p++ = *source++ );
return destin;
}