这是哈佛CS50第2,https://cs50.harvard.edu/x/2023/psets/2/substitution/周的问题.
它给了我错误
将‘char’传递给‘const char*’类型的参数的指针转换的整数不兼容;
It occurs in line 36 when I try to compile the program. I am using the cs50.dev to run the vs code in browser. From here you can use the <cs50.h>
我怎么才能修好它呢?
#include <cs50.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
int main(int argc, string argv[])
{
string pt = get_string("plaintext: ");
int len = strlen(pt);
string ct;;
string key = argv[1];
int lenkey = strlen(key);
if (lenkey < 26)
{
printf("Key must contain 26 characters.");
}
else if (argc > 2)
{
printf("Usage: ./substitution key");
}
else if (argc < 2)
{
printf("Usage: ./substitution key");
}
string keyu;
string keyl;
// Key of uppercase
for (int i = 0; i < 26; i++)
{
if (isupper(key[i]))
{
keyu = strcat(keyu, key[i]);
}
else if (islower(key[i]))
{
keyu = strcat(keyu, toupper(key[i]));
}
}
// key of lowercase
for (int i = 0; i < 26; i++)
{
if (islower(key[i]))
{
keyl = strcat(keyl, key[i]);
}
else if (isupper(key[i]))
{
keyl = strcat(keyl, toupper(key[i]));
}
}
// create cyphertext
for (int i = 0; i < len; i++)
{
if (islower(pt[i]))
{
ct = strcat(ct, keyl[pt[i] - 97]);
}
else if (isupper(pt[i]))
{
ct = strcat(ct, keyu[pt[i] - 65]);
}
else
{
ct = strcat(ct, pt[i]);
}
}
}