gir*_*una 5 c string pointers segmentation-fault
if (strlen(shortest) > strlen(longest)) {
char *temp;
strcpy(longest, temp);
strcpy(shortest, longest);
strcpy(temp, shortest);
}
}
Run Code Online (Sandbox Code Playgroud)
strcpy(longest, temp) - >导致我的程序崩溃.这是一个详细的崩溃报告(我已经包含了正确的头文件,所以它不是.编译器警告我使用未初始化的临时变量...):
程序接收信号SIGSEGV,分段故障.
__strcpy_ssse3()at ../sysdeps/i386/i686/multiarch/strcpy-ssse3.S:85
85 ../sysdeps/i386/i686/multiarch/strcpy-ssse3.S:没有这样的文件或目录.
char *temp;
strcpy(longest, temp);
Run Code Online (Sandbox Code Playgroud)
strcpy是strcpy(dst, src)不是strcpy(src, dst).源是右侧的参数,而不是左侧的参数.
而且char *temp当你通过它的价值没有被初始化strcpy.您需要分配内存temp以保存您复制的字符串,例如使用malloc
| 归档时间: |
|
| 查看次数: |
6604 次 |
| 最近记录: |