#include <stdio.h>
#include <string.h>
int main()
{
int take_photo = 0;
char command[8];
char * pictures = "take_pictures";
strcpy(command, pictures);
if (strcmp(command, "take_pictures") == 0) {
printf("%s\n", "CLICK_PHOTO_TAKEN");
take_photo = 1;
} else {
printf("%s\n", "SEG_FAULT_NO_PHOTO");
}
return 0;
}有人能告诉我为什么我总是收到SEGMENTATION FAULT错误吗?在我看来很好
可能与数组有关
发布于 2022-03-29 01:18:25
在这条线上你得到了分段故障:
strcpy(command, pictures);字符串command太小了。你想把一根长绳子复制到上面。该行为未定义。。
您可以通过使command更大来解决这个问题。例如,
char command[32];https://stackoverflow.com/questions/71655367
复制相似问题