Dev, " \t\r\n"); p; p = strtok(NULL, " \t\r\n")) { i++; ifconfig_value = (char*)malloc(20); strcpy(ifconfig_value, p); /*得到的字符串中的第二个字段是接收流量*/ if(i == 2) { rx2_tx10[0] = atol(ifconfig_value); } /*得到的字符串中的第十个字段是发送流量*/ if(i == 10) { rx2_tx10[1] = atol(ifconfig_value); break; } free(ifconfig_value); } return rx2_tx10; } int main() { long *ifconfig_result; double re_mb; /*eth0 是博主计算机上的网卡的名字*/ ifconfig_result = my_ipconfig("eth0"); /*保存在文件中的数值的单位是B,经过计算换算成MB*/ re_mb = (double)ifconfig_result[0]/(1024*1024); printf("接收流量:%0.2f MB\n",re_mb); /*保存在文件中的数值的单位是B,经过计算换算成MB*/ re_mb = (double)ifconfig_result[1]/(1024*1024); printf("发送流量:%0.2f MB\n",re_mb); }
保存文件的名字为 dele.c
运行相关的命令:
gcc -o dele dele.c
./dele
|