C 程序接收信号信号陷阱,跟踪/断点陷阱。调试中需要的帮助

C 程序接收信号信号陷阱,跟踪/断点陷阱。调试中需要的帮助,c,debugging,malloc,free,C,Debugging,Malloc,Free,该方案: #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *a = (char *)malloc(5); printf("say hello\n"); scanf("%s", a); if(!strcmp(a,"hello")) printf("\n hello"); else pri

该方案:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char *a = (char *)malloc(5);
    printf("say hello\n");
    scanf("%s", a);
    if(!strcmp(a,"hello"))
        printf("\n hello");
    else
        printf("\n say hello");
    free(a);
    system("PAUSE");
    return 0;
}
#包括
#包括
#包括
int main()
{
char*a=(char*)malloc(5);
printf(“打招呼”\n);
scanf(“%s”,a);
如果(!strcmp(a,“你好”))
printf(“\n hello”);
其他的
printf(“\n打招呼”);
免费(a);
系统(“暂停”);
返回0;
}
该程序使用代码块编写,使用c语言编译,并在windows 7中运行。 导致此错误的原因是什么(
程序收到信号信号信号陷阱、跟踪/断点陷阱。


提前谢谢

大概您的输入超过4个字符。记住,终止字符串需要1个字节。因此,您只能输入4个字符。根据strcmp(…)判断,您输入的字符数超过4个。