C language is simple to calculate the number of characters
- 2020-04-02 03:09:53
- OfStack
In this paper, an example of C language is presented to calculate the number of characters. Share with you for your reference. The details are as follows:
Char_counting. C is as follows:
#include<stdio.h>
int main()
{
long nc;
nc = 0;
while(getchar() != '0')
{
++nc;
}
printf("%ldn", nc);
}
Compile and use:
gcc char_counting.c -o char_counting.o
A common way to call:
[root@server1 c]# ./char_counting.o
123
450[ enter ]
6
Passing characters through a Linux pipe:
[root@server1 c]# echo helloworld0 | ./char_counting.o [ enter ]
10
Hope that the article described in the C programming language for you to help.