兄弟们 帮帮忙哈~c语言指针函数的有关问题
兄弟们 帮帮忙哈~c语言指针函数的问题!
题目:不断的输入数字字符,统计个数字键被按得次数
书上的答案如下:
#include "stdio.h "
#include "stdlib.h "
#include "conio.h "
#include "ctype.h "
int *cace()
{
int *pcounters;
int ch;
pcounters=(int*) malloc (10*sizeof(int));
for (ch= '0 ';ch <= '9 ';ch++)
* (pcouneters+(ch- '0 '))=0;
printf ( "input digital,please. @ for to END\n ");
while (ch=getche ())
{
if(ch== '@ ') break;
if(! isdigit (ch)) coutinue;
pcounters [ch- '0 '] ++;
}
printf( ".\n ");
return pcounters;
}
main()
{
int *pcount,k;
pcount =cace();
for (k=0;k <10;k++)
printf( "%c digital key pressed %d times. \n ",k+ '0 ',pcount[k]);
free (pcount);
}
我按照上面 一字不漏的输入,却出现以下3个错误:
1 * (pcouneters+(ch- '0 '))=0;
2 while (ch=getche ())
3 if(! isdigit (ch)) coutinue;
请问各位大虾这个是什莫问题呢?谢谢
------解决方案--------------------
//盖好了,有几个单词拼写错误,呵呵,其他没问题
#include "stdafx.h "
#include "stdio.h "
#include "stdlib.h "
#include "conio.h "
#include "ctype.h "
int *cace()
{
int *pcounters;
int ch;
pcounters=(int*) malloc (10*sizeof(int));//special
for (ch= '0 ';ch <= '9 ';ch++)
*(pcounters+(ch- '0 '))=0; //special
printf ( "input digital,please. @ for to END\n ");
while (ch=getche ())
{
if(ch== '@ ') break;
if(! isdigit (ch)) continue;//special
pcounters [ch- '0 '] ++;
}
printf( ".\n ");
return pcounters;
}
main()
{
int *pcount,k;
pcount =cace();
for (k=0;k <10;k++)
printf( "%c digital key pressed %d times. \n ",k+ '0 ',pcount[k]);
free (pcount);
}
题目:不断的输入数字字符,统计个数字键被按得次数
书上的答案如下:
#include "stdio.h "
#include "stdlib.h "
#include "conio.h "
#include "ctype.h "
int *cace()
{
int *pcounters;
int ch;
pcounters=(int*) malloc (10*sizeof(int));
for (ch= '0 ';ch <= '9 ';ch++)
* (pcouneters+(ch- '0 '))=0;
printf ( "input digital,please. @ for to END\n ");
while (ch=getche ())
{
if(ch== '@ ') break;
if(! isdigit (ch)) coutinue;
pcounters [ch- '0 '] ++;
}
printf( ".\n ");
return pcounters;
}
main()
{
int *pcount,k;
pcount =cace();
for (k=0;k <10;k++)
printf( "%c digital key pressed %d times. \n ",k+ '0 ',pcount[k]);
free (pcount);
}
我按照上面 一字不漏的输入,却出现以下3个错误:
1 * (pcouneters+(ch- '0 '))=0;
2 while (ch=getche ())
3 if(! isdigit (ch)) coutinue;
请问各位大虾这个是什莫问题呢?谢谢
------解决方案--------------------
//盖好了,有几个单词拼写错误,呵呵,其他没问题
#include "stdafx.h "
#include "stdio.h "
#include "stdlib.h "
#include "conio.h "
#include "ctype.h "
int *cace()
{
int *pcounters;
int ch;
pcounters=(int*) malloc (10*sizeof(int));//special
for (ch= '0 ';ch <= '9 ';ch++)
*(pcounters+(ch- '0 '))=0; //special
printf ( "input digital,please. @ for to END\n ");
while (ch=getche ())
{
if(ch== '@ ') break;
if(! isdigit (ch)) continue;//special
pcounters [ch- '0 '] ++;
}
printf( ".\n ");
return pcounters;
}
main()
{
int *pcount,k;
pcount =cace();
for (k=0;k <10;k++)
printf( "%c digital key pressed %d times. \n ",k+ '0 ',pcount[k]);
free (pcount);
}