C语言编写指针试题

来源:百度知道 编辑:UC知道 时间:2024/06/15 17:31:51
输入一行文字,找出大写字母,小写字母,空格,数字以及其它字符各多少?用C语言里的‘指针‘编程序。
急!!!!

下面程序我没时间调试,你自己调试一下:

#include <iostream>

int main()
{
int upper = 0,
lower = 0,
digit = 0,
space = 0,
other = 0,
i = 0;
char* p;
char s[20];

std::cout<<"Input string: ";

while ((s[i] = std::cin.get()) != '\n')
{
i++;
}
p = &s[0];
while (*p != '\n')
{
if (('A' <= *p) && (*p <= 'Z'))
{
++upper;
}
else if (('a' <= *p) && (*p <= 'z'))
{
++lower;
}
else if (' ' == *p)
{
++space;
}
else if ((*p <= '9') && (*p >= '0'))
{
++digit;
}
else
{
++other;
}
p++;
}
std::cout<<"upper case: "<<upper<<std::endl;<