我正在为 DWM(ubuntu linux)建立一个栏,显示 wifi 详细信息,例如 ssid。
那是我的代码:
#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;
}
我收到溢出错误,不知道该怎么做。我不认为,这也是获得 ssid 的好方法......:/建议?