C
cylin
Dear all,
When I use memcpy second time, it seems to be no use.
There should be two "Hello,world!" strings in this buffer.
I don't know what's wrong?
Please help, thanks.
Regards,
cylin.
----------------------------------------------
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
static unsigned char buffer[100];
class CA {
public:
int a;
char* sa;
CA(int ia):a(ia),sa(NULL) {}
};
int main(int argc, char* argv[])
{
CA A(20);
char* l_szString="Hello,world!";
A.sa=new char[strlen(l_szString)+1];
strcpy(A.sa,l_szString);
memset(buffer,0,sizeof(buffer));
memcpy(buffer,&A,sizeof(CA));
memcpy(buffer+sizeof(CA),A.sa,strlen(A.sa)+1);
for (int i=0;i<40;i++) {
cout << buffer;
}
cout << endl << "-----Finish--------" << endl;
return 0;
}
--------------------------------------------------------------------
When I use memcpy second time, it seems to be no use.
There should be two "Hello,world!" strings in this buffer.
I don't know what's wrong?
Please help, thanks.
Regards,
cylin.
----------------------------------------------
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
static unsigned char buffer[100];
class CA {
public:
int a;
char* sa;
CA(int ia):a(ia),sa(NULL) {}
};
int main(int argc, char* argv[])
{
CA A(20);
char* l_szString="Hello,world!";
A.sa=new char[strlen(l_szString)+1];
strcpy(A.sa,l_szString);
memset(buffer,0,sizeof(buffer));
memcpy(buffer,&A,sizeof(CA));
memcpy(buffer+sizeof(CA),A.sa,strlen(A.sa)+1);
for (int i=0;i<40;i++) {
cout << buffer;
}
cout << endl << "-----Finish--------" << endl;
return 0;
}
--------------------------------------------------------------------