我正在为DWM(ubuntu linux)构建一个条形图,显示了ssid等wifi细节。用cw解析ssid与iwconfig
那是我的代码:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *fp;
int status;
char path[1035];
/* Open the command for reading. */
fp = popen("iwconfig", "r");
if (fp == NULL) {
printf("Failed to run command\n");
exit;
}
char s[500];
/* Read the output a line at a time - output it. */
while (fgets(path, sizeof(path)-1, fp) != NULL) {
sprintf(s,"%s%s",s, path);
}
//printf("%s",s);
/* close */
pclose(fp);
char delimiter[1] = "s";
char *ptr;
ptr = strtok(s, delimiter);
printf("SSID: %s\n", ptr);
return 0;
}
我得到overflowerrors和不知道该怎么办。 我不认为,这是一个很好的方式来获得ssid要么...:/ 建议?
建议:**做用GDB ** – 2012-10-28 22:48:55
我不认为使用'sprintf的(一个或多个 “%s%S”,S路径);'这样积累的线是有效的。同样'char delimiter [1] =“s”'是无效的,因为它没有字符串终结符的空间。使用'char delimiter [] =“s”' –