简体   繁体   English

Unix cat -n命令实现

[英]Unix cat -n command implementation

How do i include cat -n command in my program implementation This is the problem with my program and i cant get it to print a new line number after every line so any suggestions on what i could do to rectify this 我如何在我的程序实现中包含cat -n命令这是我程序的问题,我无法让它在每行之后打印新的行号,因此,我对如何解决此问题有任何建议

if(argv[1] == "-n")
{
    fd = open(argv[i],O_RDONLY);
    printf("%d\t",line);
    while(n = read(fd,&s,1) > 0)
    {
        if(s == '00')
        {
            line++;
            printf("\n%d\t",line);
        }   
        printf("%c",s);
    }
}   
while (n = read(fd,&s,1) > 0)

missing parentheses. 缺少括号。 > has higher precedence than = . >优先级高于=

if(s == '00')

This is not how you detect an end of line. 这不是检测行尾的方式。 An end of line is typically a '\\n' character in unix-like systems. 在类unix的系统中,行尾通常是'\\n'字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM