Reputation: 335
I'm getting this error from Valgrind:
I can't see what the problem is with my code...
#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++;
}
}
Upvotes: 0
Views: 472
Reputation:
Yep as @Adri C.S. is saying:
while((*a++ = *b++) != '\0') {
*a++ = *b++;
}
make it:
while((*a++ = *b++) != '\0');
Note: The answer is given by @Adri C.S
Upvotes: 1