C语言计算字符个数


C语言计算字符个数

#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@www.bkjia.com c]# ./char_counting.o
123
450[回车]
6

通过linux管道来传递字符:

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

相关内容