数组问题
输入一行字符,分别统计出其中英文字母,空格,数字和其他字符的个数请问下用数组怎么写 这题为什么还要用数组实现?
根本用不着数组。 本帖最后由 xypmyp 于 2019-1-6 20:20 编辑
If you insist to use array instead.
// In this program you will need to look at the ASCII table, easier
_Bool debugSwitch = FALSE;
int main(void){
char charArray;
char letterAccumla = null; char numberAccumla = null; char spaceAccumla = null; char otherAccumla = null;
for(unsigned char accumla = null; accumla < sizeof charArray; accumla++){
scanf("%1c", charArray + accumla);
if((charArray < 0x005B && charArray > 0x0040) || (charArray < 0x007B && charArray > 0x0060)){
letterAccumla++;
}else if(charArray < 0x003A && charArray > 0x002F){
numberAccumla++;
}else if(charArray == 0x0020){
spaceAccumla++;
}else{
otherAccumla++;
if(charArray == 0x000A){
otherAccumla--;
break;
}
}
}
printf("letterCounter = %d\nnumberCounter = %d\nspaceCounter = %d\notherCounter = %d\n",
(unsigned int)letterAccumla, (unsigned int)numberAccumla, (unsigned int)spaceAccumla, (unsigned int)otherAccumla);
return 0;
}
页:
[1]