【发布时间】:2022-01-22 06:58:48
【问题描述】:
我想将两个变量传递给 C 中的函数 - 一个是字符串,另一个是字符串中的单个字符。
但是,我不确定如何在不出现“预期表达式”错误的情况下使用该函数:
int spaces_away(string cipher[], string plain[char i]);
或也出现“未声明的标识符”错误:
int spaces_away(string cipher[], char plain[i]);
我认为添加变量“i”来自代码中的“for”循环也很重要,这就是我的代码在 main 中的样子:
{
// Error if there are not two arguments
if (argc != 2)
{
printf("Command Line Must Have Two Arguments\n");
return 1;
}
// Error if there are not 26 characters in encryption
else if (strlen(argv[1]) != 26)
{
printf("Cipher must have 26 characters\n");
return 1;
}
else
// Takes a word and encrypts it by a user given alphabet
{
string stdWord = get_string("plaintext: ");
for (int i = 0, n = strlen(stdWord); i < n; i++)
{
encrypt[i] = (stdWord[i] + spaces_away(argv[1], tolower(stdWord[i]));
}
printf("ciphertext: %s\n", (string) encrypt);
return 0;
}
}
【问题讨论】:
-
这被标记为
c。 C 没有内置的string类型,你自己定义了吗?如果是这样,那将是一个答案。 -
@marco-a 这看起来很像
cs50问题。string是char *并且库代码有一个get_string函数
标签: c parameters char typedef function-declaration