关于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);

 

posted @ 2019-03-09 21:15  卷积  阅读(258)  评论(0编辑  收藏  举报