If statement 错误的if语句(初学者)

If statement 错误的if语句(初学者),if-statement,cs50,If Statement,Cs50,我在cs50 edx的第2周,在尝试编译时不断出现以下错误: caesar.c:23:7:错误:isalphaencryptme的预期表达式[p]= 真的{ ^ 这是我的密码: #include <stdio.h> #include <cs50.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, string argv[])

我在cs50 edx的第2周,在尝试编译时不断出现以下错误:

caesar.c:23:7:错误:isalphaencryptme的预期表达式[p]= 真的{ ^

这是我的密码:

#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(int argc, string argv[])
{
    if (argc !=2) { 
    printf("ERROR: Must pass exactly two command line arguments!\n");
    return 1;}  

   string num = argv[1];
   int i = atoi(num);

   printf("plaintext: ");

   string encryptme = get_string();

   printf("cyptertext: ");

   for (int p = 0; p <= strlen(encryptme); p++)(
      if ( isalpha(encryptme[p]) = true){
      printf("%c",encryptme[p]+i%26);
      }
   )
}
盯着这个看了一个多小时,搜索了一个多小时,请找到我毫无疑问的愚蠢错误!

你需要==而不是=

前者是一种平等测试,后者是一种分配

然而,最好不要和真实相比较,最好只是说

if (isalpha(encryptme[p]))
另外,在C中也要小心使用true。并非所有版本的C都支持true。我不确定cs50.h中有什么。可能true在那里,可能不是

我会这样做:

for (int p = 0; p <= strlen(encryptme); p++) {
    if (isalpha(encryptme[p])) {
        printf("%c", encryptme[p] + i % 26);
    }
}
清理了一些间距和缩进,使之更为传统。另外,您应该接受jdow的回答,因为这是首先检测for{的地方。

您的for循环
对于int p=0;p也-这应该是在提示用户输入字符串进行加密后创建一个相对简单的密码。命令行应该接受两个参数,第一个参数调用程序,第二个参数是a,以将密码设置为基础。如果isalphaencryptme[p]=true,则将其更改为如果isalphaencryptme[p]==trueThank you-这肯定是一个错误,但我修复并重新编译后仍然收到相同的错误消息。很有趣,但cs50.h必须合并。它在进行其他更正后进行编译。谢谢。这一点,再加上Ray的帮助,使它得以编译。很高兴提供帮助,如果它有效,请单击接受答案。