C language - character counts 2

C language - the character counts 2
subject description
written a function, the argument came a string, count the number of letters, numbers, spaces, and other characters in the string, the input string in the main function and outputs the result. As long as the results, what message do output.

Input
line string
output
statistical data, four separate numbers, spaces.
Sample input
! @ # $% ^ QWERT 1234567
sample output
5746

# include<stdio.h>
# include<string.h>
# include<ctype.h>
void count(char ch1[],int m,int ch2[],int n);
int main()
{
	char ch1[10000];
	int m,n,i,ch2[4]={0};
	gets(ch1);
	m=strlen(ch1);n=4;
	count(ch1,m,ch2,n);
	for(i=0;i<4;i++)
	{
		printf("%d ",ch2[i]);
	}
	return 0;
 } 
 void count(char ch1[],int m,int ch2[],int n)
 {
 	int i,j,k;
 	for(i=0;i<m;i++)
 	{
 		j=1;
 		if(isalpha(ch1[i]))
 		{
 			ch2[0]++;j=0;
		  } 
 		if((ch1[i]>=48)&&(ch1[i]<=57))
 		{
 			ch2[1]++;j=0;
		 }
 		if(ch1[i]==' ')
 		{
 			ch2[2]++;j=0;
		 }
		 if(j)
		 {
		 	ch2[3]++;
		 }
	 }
 }

Note: similarities and differences with scanf gets in. scanf () and gets () marks the end
gets () as a carriage return end of the string, while the carriage away from the read buffer, but not as part of a string
scanf () a space, a carriage return , tabs as terminator strings, do not go reading spaces, tabs, carriage returns, remains in the buffer

Published 123 original articles · won praise 8 · views 20000 +

Guess you like

Origin blog.csdn.net/Du798566/article/details/104899321