Unhandled exception 的问题

justdy 2008-09-13 10:20:57
#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 _tmain(int argc, _TCHAR* argv[])
{

char *pstr;
pstr = (char *)malloc(sizeof(char) * NUM);
printf("input a string:\n");
gets(pstr);
PNUMBERS *presult;
presult = count(pstr);
}

一调用(*pcount)->letter++;就会爆出这个Unhandled exception的错误,高手帮忙改下。谢谢
...全文
468 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
kkk215215 2008-09-13
  • 打赏
  • 举报
回复
报错的时候,会有错误提示的.然后到MSDN里找,可以找到错误提示的原因,然后自己改.
wangdeqie 2008-09-13
  • 打赏
  • 举报
回复

//改成这样
#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;
}

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧