c-CS50 Pset 2 Caesar---验证密钥



试图让此代码拒绝20x(以及其他类似的输入(。它拒绝xyz和x2,但不拒绝20x。我的循环好像有问题。。。

有什么建议吗?

#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
bool is_digit (string s);
int main (int argc, string argvc[]) {
if (argc != 2 || !is_digit(argvc[1]))
{
printf("Usage: ./caesar keyn");
}
else 
{
printf("Successn");
printf("%sn", argvc[1]);
}
}
bool is_digit(string s) { 
int n = strlen (s);
for (int i=0; i < n ; i++)
{
char x = s[i];
if (!isdigit(x))
{
return false;
}
return true;
}
return 0;
}

is_digit函数测试s的第一个字符,然后返回main。返回将结束函数,因此for循环不会继续迭代。

最新更新