Caesar problem code generating "error: implicitly declaring library function 'strlen' with type 'unsigned long (const char *)'
Caesar problem code generating "error: implicitly declaring library function 'strlen' with type 'unsigned long (const char *)'
我正在学习 CS50 课程并且在第 2 周。第 2 周的问题之一称为“Caesar”。本质上,您必须编写代码,通过移动使用用户输入的首选数字的字母来加密文本。在 运行 我的代码之后,我不断收到此错误
"error: implicitly declaring library function 'strlen' with
type 'unsigned long (const char *)'
[-Werror,-Wimplicit-function-declaration]
for(i = 0, l = strlen(text); i < n; i++)"
这是代码:
int main(int argc, string argv[])
{
string n = argv[1];
int y = argc;
int key = get_int("./caesar ");//getting the number from the user
int k = (key);//assigning key a variable name.
string text = get_string("plaintext: ");//letting the user input their text.
if (key < 1)//Trying to make limit for acceptable input.
{
printf("ERROR");
return 1;
}
int l;
int i;
//for loop containing the encipher process
for(i = 0, l = strlen(text); i < n; i++)
{
if(isalpha(i))
{
if (isupper[i])
{
printf("ciphertext: %c",(text[i] + k)%26 + 65);
}
else (islower[i])
{
printf("ciphertext: %c",(text[i] + k)%26 + 65);
}
}
}
printf("ciphertext: %c", d || c);
return;
int checking_key(int y,string n)
int num = argc;
string key = y;
int num_key = atoi(key);
if(argc != 2)
{
return 0;
}
else
{
if (num_key > 0)
{
return num_key;
}
else
{
return 0;
}
}
}
来自man strlen:
Synopsis
#include <string.h>
size_t strlen(const char *s);
就像需要“包含”cs50.h
才能使用任何 get_*
功能一样,string.h
必须“包含”才能访问其功能,例如 strlen
.
另外(根据评论):
编译错误中的“有序比较”
ordered comparison between pointer and integer ('int' and 'string' (aka 'char *')) [-Werror] for(i = 0, l = strlen(text); i < n; i++)
是i < n
。错误说其中一个是整数,其中一个是字符串。
经过仔细检查,该程序是 long 干净编译的方式。建议您遵循规范并“一次一步解决这个问题”
我正在学习 CS50 课程并且在第 2 周。第 2 周的问题之一称为“Caesar”。本质上,您必须编写代码,通过移动使用用户输入的首选数字的字母来加密文本。在 运行 我的代码之后,我不断收到此错误
"error: implicitly declaring library function 'strlen' with type 'unsigned long (const char *)' [-Werror,-Wimplicit-function-declaration] for(i = 0, l = strlen(text); i < n; i++)"
这是代码:
int main(int argc, string argv[])
{
string n = argv[1];
int y = argc;
int key = get_int("./caesar ");//getting the number from the user
int k = (key);//assigning key a variable name.
string text = get_string("plaintext: ");//letting the user input their text.
if (key < 1)//Trying to make limit for acceptable input.
{
printf("ERROR");
return 1;
}
int l;
int i;
//for loop containing the encipher process
for(i = 0, l = strlen(text); i < n; i++)
{
if(isalpha(i))
{
if (isupper[i])
{
printf("ciphertext: %c",(text[i] + k)%26 + 65);
}
else (islower[i])
{
printf("ciphertext: %c",(text[i] + k)%26 + 65);
}
}
}
printf("ciphertext: %c", d || c);
return;
int checking_key(int y,string n)
int num = argc;
string key = y;
int num_key = atoi(key);
if(argc != 2)
{
return 0;
}
else
{
if (num_key > 0)
{
return num_key;
}
else
{
return 0;
}
}
}
来自man strlen:
Synopsis
#include <string.h>
size_t strlen(const char *s);
就像需要“包含”cs50.h
才能使用任何 get_*
功能一样,string.h
必须“包含”才能访问其功能,例如 strlen
.
另外(根据评论):
编译错误中的“有序比较”
ordered comparison between pointer and integer ('int' and 'string' (aka 'char *')) [-Werror] for(i = 0, l = strlen(text); i < n; i++)
是i < n
。错误说其中一个是整数,其中一个是字符串。
经过仔细检查,该程序是 long 干净编译的方式。建议您遵循规范并“一次一步解决这个问题”