char temp[50], voltage[50], offset[50], wr1_linkt[50], wr1_loop[50], wr1_onew[50], wr0_linkt[50], wr0_loop[50], wr0_onew[50], time[50]; char buffer[1024]; int counter = 0; FILE *fp = popen("/usr/bin/sn_core.elf getstat 2>/dev/null","r"); if(fp == NULL){ printf("Failed to run\n"); exit(0); } fgets(buffer,sizeof(buffer),fp); char *p = strstr(buffer,"mu:"); sscanf(p,"%*[^0123456789]%[^ ]",wr1_loop); printf("%s\n",wr1_loop[0]); p = strstr(buffer,"dms:"); sscanf(p,"%*[^0123456789]%[^ ]",wr1_onew); printf("%s\n",wr1_onew[0]); p = strstr(buffer,"crtt:"); sscanf(p,"%*[^0123456789]%[^ ]",wr1_linkt); printf("%s\n",wr1_linkt[0]); p = strstr(buffer,"temp:"); sscanf(p,"%*[^0123456789]%[^ ]",temp); printf("%s\n",temp[0]); p = strstr(buffer,"Time:"); sscanf(p,"%*[^0-9+-]%[^.]",time); printf("%s\n",time[0]); pclose(fp); return 0; 出现Segmentation fault
时间: 2024-04-27 11:25:24 浏览: 70
DisplayPort Link training optimization_surekqh_displayport_Linkt
5星 · 资源好评率100%
出现 Segmentation fault 错误通常是因为程序访问了不可访问的内存地址,导致程序崩溃。在代码中,可能是因为数组越界或者指针没有被正确初始化等原因导致了该错误。可以通过调试工具来找出错误的具体位置,并进行相应的修复。另外,你的代码中输出变量时使用了 %s,但是变量类型是 char 类型的数组,应该使用 %c 来输出单个字符。
阅读全文