C语言计算字符个数

来源:互联网 发布:xnview中文版官方 mac 编辑:程序博客网 时间:2024/05/01 06:50

#include<stdio.h>
int main()
{
    long nc;
    nc = 0;
    while(getchar() != '0')
        {
            ++nc;
        }
    printf("%ld/n", nc);
}

 

gcc char_counting.c -o char_counting.o

 

一种通常的调用方式:

[root@myhost c]# ./char_counting.o
123
450[回车]
6


通过linux管道来传递字符:

[root@myhost c]# echo helloworld0 | ./char_counting.o [回车]
10
[root@myhost c]#


原创粉丝点击