wenjian.c

来自「一个linux下用c 写得读取路由表的小程序。」· C语言 代码 · 共 42 行

C
42
字号
#include <stdio.h>#include <string.h>#include <stdlib.h>main( ){FILE *fp;char ch;char *str[13];char str1[15];int m;int i=1,j=0;system("route >/root/routetable");if ((fp=fopen("/root/routetable","rt"))==NULL){printf("cannot open file! \nplease strike any key exit !");getchar();exit(1);}ch=fgetc(fp);while(ch!=EOF){if((ch=='\n')&&(i!=0)){i--;ch=fgetc(fp);continue;}if((ch=='\n')&&(i==0)){fgets(str1,12,fp);str[j]=strdup(str1);j++;ch=fgetc(fp);continue;}ch=fgetc(fp);}m=j;for(j=0;j<m-1;j++)printf("%s\n",str[j]);fclose(fp);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?