我从Valgrind那里得到这个错误:
我看不出我的代码有什么问题......
#include <iostream>
using namespace std;
void strcat2(char* a, char* b);
int main()
{
char *a = new char[2010], *b = new char[1000];
while (cin.getline(a, 1000) && cin.getline(b, 1000))
{
cout << "a = \"" << a << "\";" << endl;
cout << "strcat2(a, \"" << b << "\");" << endl;
strcat2(a, b);
cout << "a = \"" << a << "\";" << endl << endl;
}
delete[] a;
a = NULL;
delete[] b;
b = NULL;
return 0;
}
void strcat2(char* a, char* b){
while (*a){
a++;
}
while((*a++ = *b++) != '\0'){
*a++ = *b++;
}
}
答案 0 :(得分:1)
是的,正如@Adri C.S.所说:
while((*a++ = *b++) != '\0') {
*a++ = *b++;
}
制作:
while((*a++ = *b++) != '\0');
注意:答案由@Adri C.S
给出