省略字符 z 和 y 的字符串数组
string array omiting characters z and y
im 为我的实验室做一项作业,这与将字符串从另一个文件加密到文本文件中有关,效果很好,但我唯一的问题是当我加密或解密加密时,加密省略了字母 Z 和 Y。我尝试改变一些事情,但没有任何效果,如果你知道如何解释,因为我迷路了。
这是我到目前为止的代码:
#include iostream
==
#include fstream
==
#include cstring
==
#include string
==
using namespace std;
int main()
{
ifstream inputFile;
ofstream outputFile;
const int SIZE=150;
char file[SIZE];
char message[SIZE+1];
char letter;
char alphabet[]={'A','B','C','D','E','F','G','H','I','J','K','L',
'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',' '};
cout<<"Enter the message you want to encrypt: "<<endl; //getmessage
cin.getline(message,SIZE,'n');
for(int i=0;i<strlen(message);i++){
if(islower(message[i])) //change to
message[i]=toupper(message[i]); //uppercase
}
outputFile.open("textoNoEncrypt.txt");
for(int i=0;i<strlen(message);i++){ //copy message to
outputFile.put(message[i]); //file
}
outputFile.close();
inputFile.open("textoNoEncrypt.txt");
if (inputFile.is_open()){
int i=0;
while (!(inputFile==' ')){
inputFile>>file[i]; //reading and copying
i++; //data from file
}
}
inputFile.close();
outputFile.open("textoEncrypt.txt");
for(int i=0;i<strlen(file);i++){
int j=0;
int P=0;
int index=0;
bool found=false;
while(!found){
if(file[i]==alphabet[j]){
P=j;
index=(P+3)%26; //encrypting message
file[i]=alphabet[index];
found=true;
cout<<j<<" ";
}
j++;
}
outputFile.put(file[i]);
}
outputFile.close();
cout<<message<<endl; //show original message
cout<<file<<endl; //show encrypted message
return 0;
}
我认为这是由 P+3 线引起的
相关文章:
- 将C#字符串数组传递给C++
- 如何为 C 型字符串数组编写 getter 和 setter?
- 有没有办法使用 strcpy 将字符串数组复制到另一个字符串或其他数组中?
- 尝试将 c 字符串数组与分隔符连接起来
- 将字符串数组传递给接受常量字符**的函数
- 返回 C++ 中的字符串数组
- 如何从COM模块中的函数返回字符串数组?
- 无法将字符串数组声明为类成员而不是字符 (C++)
- 删除字符串数组
- 如何将字符串数组返回到 java JNI
- 将字符串数组作为函数参数传递
- C++将字符串数组的元素存储到变量中
- 循环访问还包含未使用元素的字符串数组
- 字符串数组上的 sizeof 运算符以 C++ 为单位给出不同的输出
- 乘以字符串/数组和全局数组
- 递归二进制搜索与字符串数组
- 如何初始化一个标准::字符串数组?
- 无法在声明时使用初始值设定项列表初始化常量字符*/字符串数组的向量
- C++字符串数组的动态向量
- 给定一个等长字符串数组