69,382
社区成员
发帖
与我相关
我的任务
分享
//改成这样
#include <stdio.h>
#include <malloc.h>
#define NUM 100
typedef struct numbers
{
int letter;
int num;
int blank;
int others;
}NUMBERS,*PNUMBERS;
PNUMBERS count(char *p)
{
PNUMBERS pcount = NULL;
int i = 0;
pcount = (PNUMBERS)malloc(sizeof(PNUMBERS));
while (*(p+i) != '\0')
{
if ((*(p+i) > 'a' && *(p+i) < 'z') || (*(p+i) > 'A' && *(p+i) < 'Z'))
{
pcount->letter++;
}
else if (*(p+i) > '0' && *(p+i) < '9')
{
pcount->num++;
}
else if (*(p+i) == ' ')
{
pcount->blank++;
}
else
pcount->others++;
i++;
}
return(pcount);
}
int main(int argc, char* argv[]) //
{
char *pstr;
pstr = (char *)malloc(sizeof(char) * NUM);
printf("input a string:\n");
gets(pstr);
PNUMBERS presult;
presult = count(pstr);
return 0;
}