关于c中memcpy的使用

unsigned char *temp; 
memcpy(temp, ptrCurrSamples,
sizeof(unsigned char)*(numOfSamples-1)*4);

在使用memcpy直接拷贝到temp地址中,出现段错误。 

stackoverflow搜说是temp没有分配空间, 是一个空指针,所以会出现段错误。

https://stackoverflow.com/questions/26793463/segmentation-fault-when-using-memcpy。

修改后

unsigned char c = 'n';
unsigned char *temp = &c; 
memcpy(temp, ptrCurrSamples, sizeof(unsigned char)*(numOfSamples-1)*4);
The Safest Way to Get what you Want is to Try and Deserve What you Want.
原文地址:https://www.cnblogs.com/Shinered/p/10503073.html