centos learning: What is fgetc () fgets () cat more is how come?

fgetc after reading a character pointer moves a read until EOF stop

fgets read pointer is moved down one row until feof (FILE * fp) to determine whether the reading

char chs [a defined length]
fgets (CHS, the number of bytes to read, fp)


vim god_more.c

#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[])
{
    FILE *fp=fopen(argv[1],"r");
    char chs[100];
    fgets(chs,100,fp);
    int i=0;
    int from=0;
    //指针数组 指向的都是 指针
    char *get_arg=argv[2];
    //指针默认指向第一位 用以判断 +
    if(argc==3 && *get_arg=='+')
    {
        get_arg++;
        from=atoi(get_arg)-1;
    }

    while(!feof(fp)){
        if(i>=from)
            printf("%s",chs);
        fgets(chs,100,fp);
        i++;
    }
    fclose(fp);
    return 0;
}

使用:
god_more dc.txt +3

read all about the cat command word

more 命令
more dc.txt more +5 dc.txt
more +/dc dc.txt
| 组合命令

ls | more +3 显示目录的三条

组合命令的意思是 把前面执行的结果 作为后面执行的参数
Published 65 original articles · won praise 3 · views 50000 +

Guess you like

Origin blog.csdn.net/web_orange/article/details/73588144