如何跳过字符数组的空格
How to skip whitespaces for a character array?
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
char input[100],crypt[100],decrypt[100];
int key,key1[100],j=0,i;
cout << "Enter plaintxt:";
gets_s(input);
cout << "Enter key:";
cin >> key;
key1[0] = key;
for (int i = 1; i < strlen(input); i++){
if (input[i - 1] >= 97 && input[i - 1] <= 122)
key1[i] = ((int)input[i-1])-97;
}
for (int j = 0; j < strlen(input); j++){
cout << key1[j]<<" ";
}
for ( i = 0; i < strlen(input); i++){
crypt[i] = (char)((key1[i] + (int)(input[i]-97)) % 26+97);
}
crypt[i] = ' ';
cout << crypt;
//decrypt[0] = ((int)crypt[0] - 97)-key;
//cout << decrypt[0];
_getch();
}
我的输入是:攻击很好,我的密钥是 12,我的输出应该是:mtmtcm sa ljrdy.....注意:这是一种单字母密码
由于问题仅与空格字符有关,因此在接受用户输入后调用此函数将解决问题,因为它将删除空格:
void RemoveSpaces(char* IN_cpSource)
{
if (IN_cpSource == NULL)
{
exit(1);
}
char* cpResult = IN_cpSource;
do
{
*cpResult = *IN_cpSource;
if (*cpResult != ' ')
{
cpResult++;
};
}while (*IN_cpSource++ != 0);
}
相关文章:
- 2D数组来自文本输入,中间有空格
- 如何将以逗号和空格分隔的整数读取到 2D 数组中?
- 如何在 C++ 中从文件中读取字符数组(带有一些空格)
- 防止在字符数组中输入双倍空格在 C++
- 使用空格分隔符从文本文件将对象读入数组
- 用空格填充 2D 数组(从文件输入)
- 从字符数组中删除双空格
- 循环以从字符数组中删除过多的空格 (C++)
- 如何在 c++ 中将文件中的无空格插入器读取到数组中?
- 获取由空格分隔的未知大小的单行输入,并将其存储到整数数组中
- 在 C++ 中输入带有空格的字符数组
- 2D数组排序,空格打乱顺序
- 2D 数组如何允许输入中的空格
- 如果 strlen 在 char 数组之间遇到空格,它会怎么做
- 按空格拆分字符串并将列输出到不同的数组中
- 缓冲区用不需要的数据填充 char 数组中的最后一个空格
- 如何修改数组,从中删除空格,然后将其存储在新数组中
- 为什么数组(字符串类型)的大小是 24 字节,带有单个空格元素
- 我正在尝试在字符数组的中间添加一个空格.不确定如何正确移动它
- 使用scanf()在数组中获取字符(不与空格分开)