0
试图解决由教师提供的问题之一,并且我无法正确理解如何正确调用此功能。使用cctype库搜索功能以查找范围中数字的字符数
我收到了一个链接到测试驱动程序的函数,我的目标是使用cstring库在随机生成的字符串对象中使用此函数查找0-9范围内的任何数字。
int countDigits(char * const line) {return 0;}
到目前为止,这是我:
int countDigits(char * const line)
{
int i, index;
index = -1;
found = false;
i = 0;
while (i < *line && !found)
{
if (*line > 0 && *line < 9)
index++;
}
return 0;
}
我的代码不是很大而且目前只会导致一个无限循环和失败,任何帮助将是非常赞赏。
IMO,这是细节的这样一个问题,几乎完美的程度 - 提供有关如何编写代码,而不只是提供指导预写码。做得好。 –
是的我的代码有点灾难性哈哈,但是感谢你指引我朝着正确的方向发展,并找到了实现它所需要的功能。以下是修改后的代码的样子: int countDigits(char * const line) { char index = * line; int count; (指数) if(index> 48 && * line <57) count ++; while(!index) if } return count; } – RyeMan
很高兴能帮到你! –