C语言简单实现计算字符个数的方法
本文实例讲述了C语言简单实现计算字符个数的方法。分享给大家供大家参考。具体如下:
char_counting.c如下:
#include<stdio.h>
intmain()
{
longnc;
nc=0;
while(getchar()!='0')
{
++nc;
}
printf("%ld\n",nc);
}
编译和使用下:
gccchar_counting.c-ochar_counting.o
一种通常的调用方式:
[root@server1c]#./char_counting.o 123 450[回车] 6
通过linux管道来传递字符:
[root@server1c]#echohelloworld0|./char_counting.o[回车] 10
希望本文所述对大家的C语言程序设计有所帮助。