为什么strcpy()的代码会给我一个分段错误?我正在使用GNU,当代码达到strcpy时,它就会因为分段错误而失败.
#include<stdio.h>
#include<string.h>
#include<assert.h>
void PrintString(char *buff);
int main()
{
char *buffPtr = malloc(128);
assert(&buffPtr != NULL);
memset(&buffPtr, 0, sizeof(buffPtr));
strcpy(buffPtr, "This is my string");
free(buffPtr);
return 0;
}
Run Code Online (Sandbox Code Playgroud) c ×1