- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
由于这些错误,以下程序拒绝编译:
vigenere.c:52:31: error: incompatible integer to pointer conversion assigning to
'string' (aka 'char *') from 'int' [-Werror,-Wint-conversion]
...ciphertext[i] = ((((plaintext[i] - 65) + keyword[num % keylength]) % 26) + 65);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vigenere.c:56:31: error: incompatible integer to pointer conversion assigning to
'string' (aka 'char *') from 'int' [-Werror,-Wint-conversion]
...ciphertext[i] = ((((plaintext[i] - 97) + keyword[num % keylength]) % 26) + 97);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
下面是程序,旨在实现一个简单的 vigenere 密码:
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
int main(int argc, string argv[])
{
if(argc != 2)
{
printf("Invalid input; try again!\n");
return 1;
}
else if(argv[1])
{
for(int i = 0, n = strlen(argv[1]); i < n; i++)
{
if(!isalpha(argv[1][i]))
{
printf("Invalid input; try again!\n");
return 1;
}
}
}
// get plaintext from user
string plaintext = GetString();
string ciphertext[100];
int num = 0;
string keyword = argv[1];
int keylength = strlen(keyword);
// change key values from letters to shifts
for(int i = 0, n = keylength; i < n; i++)
{
if(isupper(keyword[i]))
{
keyword[i] = keyword[i] - 65;
}
else if(islower(keyword[i]))
{
keyword[i] = keyword[i] - 97;
}
}
for(int i = 0, n = strlen(plaintext); i < n; i++)
{
if(isalpha(plaintext[i]))
{
if(isupper(plaintext[i]))
{
ciphertext[i] = ((((plaintext[i] - 65) + keyword[num % keylength]) % 26) + 65);
}
else if(islower(plaintext[i]))
{
ciphertext[i] = ((((plaintext[i] - 97) + keyword[num % keylength]) % 26) + 97);
}
num++;
}
// non-alphabetic characters
else
{
ciphertext[i] = plaintext[i];
}
printf("%c", ciphertext[i]);
}
printf("\n");
}
我不知道为什么编译器会抛出错误,因为我有一个旧版本的程序,几个月前编译的(代码在第 52 行和第 56 行完全相同)工作正常。
我真的很感激任何和所有的帮助:)
最佳答案
变量ciphertext
是char*
的数组,我觉得应该是:
char ciphertext[1000]
关于c - "Incompatible integer to pointer conversion",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31653813/
有没有人有嵌套 Intent 的好例子,尤其是在 #yes 和 #no 是子节点的情况下。我得到的情况是 API 返回的是 Intent 值,但输出文本来自“Anything else”! 最佳答案
我知道您可以转到 Watson Conversation 界面,右键单击工作区,然后下载工作区的 JSON,其中包含意图,如下所示:Is there any way to export intents
我能否在 Watson Conversation API 的对话流中使用节点条件中的意图置信度评级? 最佳答案 要做到这一点,请创建一个条件来寻找您的意图,然后检查置信度。 你会拥有的示例条件 #te
我找到了很多关于这个错误的帖子,但我可以找到克服它的方法。这是触发错误的代码: void main(){ float f{1.3}; } 为什么在初始化列表中没有像其他变量那样发生转换?例如,
我有以下代码。 #include using namespace std; class Base { public: virtual int f(){coutf(); ///base
Visual C++ 2017 和 gcc 5.4 产生 conversion from 'const unsigned char' to 'const float' requires a narro
我正在为 PIC18F2420 使用带有 xc8 1.35 编译器的 MPLABX 3.20,我收到了两个我不理解的奇怪警告: 这是生成警告的源代码之一 9 void write(Pin _Pin,
我正在尝试在 win32 API(无 mfc)上编写一些直接的 c++。有了这个更现代的 c++ 编译器,我得到: 警告 C4838:从“unsigned int”到“int”的转换需要收缩转换 它发
此代码采用用户输入(字符 C、T、B)和(int 0-24 和 0-60)来计算 parking 成本关于用户输入的车辆类型。 我怀疑错误发生在函数 charged 中,因此我无法在收到此错误的最后一
为什么在使用 tuple 或 Tuple 转换向量时会得到以下不同的结果? julia> a = [1, 2, 3] 3-element Vector{Int64}: 1 2 3 julia> tup
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 8年前关闭。 Improve t
我正在开发一个文件共享网站,我需要一种方法来对上传的文档进行截图。 该站点将支持多种文件格式,从纯文本到办公文档(doc、xls、ppt...)、视频(mpeg、avi...)、图像(jpg、gif、
在 VHDL 中是否有将整数类型对象转换为实数类型的通用转换函数? 这是针对测试平台的,因此可综合性不是问题。 最佳答案 您可以将整数转换为实数,如下所示: signal i: integer; si
如何在 Ocaml 中将字符串选项数据类型转换为字符串? let function1 data = match data with None -> "" | Some str -> s
我已经在 VHDL 中编写了一个算法,但是我有一条消息,我不明白“sra/sla 在这种情况下不能有这样的操作数。”。请问有什么帮助吗? library ieee; use ieee.std_logi
我经常需要将数据从一种类型转换为另一种类型,然后进行比较。一些运算符会先转换为特定类型,这种转换可能会导致效率损失。例如,我可能有 my $a, $b = 0, "foo"; # initial va
假设我在 IBM Watson 中配置了一个对话服务,可以识别以单词和片段形式给出的数字。例如,如果我有号码 1320 , 可以发送为 thirteen twenty或 thirteen two ze
也许我错过了一些显而易见的事情...在整个文档中,我似乎都认为Kotlin具有各种类型的序列,这些序列不能互操作。即使复制序列可能效率不高–当我需要将其作为语义相同但不同的类型传递给函数时,这也无济于
在我的Linux终端中,我想要使用QTcpSocket从qt运行以下“对话”: S user@domain:~ $ netcat 1.1.1.2 9230 R HELO SOME MORE I
我有一个模板函数,其中枚举类型转换为它的底层类型,工作正常,但我写了一个重载,它应该接受一个整数并返回它自己,它给我一个错误,指出 int 不是枚举类型。在我的模板中,这应该已经被过滤掉了。怎么了?
我是一名优秀的程序员,十分优秀!