Home > Back-end >  The statistical characters of English input line of characters, the number of character Spaces and o
The statistical characters of English input line of characters, the number of character Spaces and o

Time:06-07

# include & lt; stdio.h>
#include
Int main (void)
{
Int I, number=0, English=0, space=0, other=0;
Char a, [11].
Printf (" input 10 characters: ");
for(i=0; A [I]!='\ 0'; I++)
{
The scanf (" % s ", a [I]);
}
for(i=0; i<10; I++)
{
If (isalnum (a) [I]) number++;
Else if (isalpha (a) [I]) english++;
Else if (isspace (a) [I]) space++;
The else other++;
}
Printf (" % d characters in English with \ n % d numeric characters with a total of % d a \ n \ n space characters other characters, a total of % d ", English, number, space and other);
return 0;
}
Don't run, for help

CodePudding user response:

for(i=0; A [I]!='\ 0'; I++)
{
The scanf (" % s ", a [I]);
}
Can you tell me what is this operation, if you want to enter a string, there is no need for a for loop, if you want to input characters, use % c, don't know what are you doing

CodePudding user response:

# include & lt; stdio.h>
#include
Int main (void)
{
Int I, number=0, English=0, space=0, other=0;
Char a, [11].
Printf (" input 10 characters: ");
Gets (a);
for(i=0; i<11. I++)
{
If (isalnum (a) [I]) number++;
Else if (isalpha (a) [I]) english++;
Else if (isspace (a) [I]) space++;
Else if (isalnum (a [I])==0 & amp; & Isalpha (a [I])==0 & amp; & Isspace (a [I])==0) other++;
}
Printf (" % d characters in English with \ n % d numeric characters with a total of % d a \ n \ n space characters other characters, a total of % d ", English, number, space and other);
return 0;
}

CodePudding user response:

I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related