在函数中通过引用从数组复制到数组
Copy from array to array by refenrence in function
我不知道为什么它不起作用。更重要的是,我甚至不能说错误是关于什么;/有人能解释一下错误是关于什么的吗?
代码应该:创建一个像"妈妈"这样的字符串。然后创建二维数组,用字符串填充它。空闲空间用_填充。所以妈妈盒子=
[m] [o]
[m] [_]
现在用列后面的文本填充下一个数组。填充到新数组的Mom_将看起来像mmo_。然后我计算加密文本。我希望你明白我做了什么:D
这里是代码
//wal = kolumny=wiersze
#include <cstdlib>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
void pole(int &a,const int &l);
void tab(const char &s[],char &d[], char &f[],const int a);
int main(){
string code;
cin >> code;
int wall=1;
int d=code.length();
char tekst[d];
pole(wall,d);
strcpy(tekst,code);
char kw[wall][wall];
char szyfr[d];
tab(tekst,kw,szyfr,wall);
for (int i=0;i<d;i++)
cout << szyfr[i] << endl;
system("PAUSE");
return 0;
}
void pole(int &a,const int &l){
if (a*a < l)
pole(a+=1,l);
}
void tab(const char &s[],char &d[], char &f[],const int a){
int i=0;
for (int x=0;x<a;x++,i++){
for (int y=0;y<a;y++,i++){
if(s[i])
d[x][y]=s[i];
else d[x][y]=='_';
f[i]=d[x][y];
}
}
}
d[x][y]
在tab
中没有意义。您必须将第一个维度作为参数传递,并在索引时使用它。比如:
void tab(const char &s[],char* &d, char &f[],const int a, int d_num_cols){
int i=0;
for (int x=0;x<a;x++,i++){
for (int y=0;y<a;y++,i++){
if(s[i])
d[x*d_num_cols + y]=s[i];
else d[x*d_num_cols + y]=='_';
f[i]=d[x*d_num_cols + y];
}
}
}
相关文章:
- 有没有办法使用 strcpy 将字符串数组复制到另一个字符串或其他数组中?
- 如何将一个结构的字符数组复制到结构的另一个字符数组中?
- 将字符数组复制到 QByte 数组中,而无需传递指针
- std::transform 将一个结构数组复制到另一个结构数组
- 如何使用指针C++将元素从2D数组复制到1D数组
- 如何将 int4 数组复制到 int8 向量中
- 如何将多维字符数组复制到字符 * 中
- std::将三维数组复制到三维向量中
- 为什么我不能将 C 样式数组复制到 std::array?
- 有没有办法将最初作为字符串输入的数字字符数组复制到双向链表中
- 为什么当我想将(使用 memcpy)结构数组复制到字符数组时,字符数组为空
- 如何将数据从数组复制到C++特征矩阵或向量
- 将数组复制C++作为特征矩阵的向量
- 如何在 c++ 中将数组复制到文件
- 如何将对象数组作为构造函数中的参数传递,然后将传递的数组复制到另一个数组(仍在构造函数中)
- CUDA 将大于线程计数的数组复制到共享内存
- 可以使用 std::copy 将 3D 数组复制到矢量
- 如何在C++中将本地字符串数组复制到私有成员字符串数组
- 如何使用 std::copy 将一个 constexpr 数组复制到另一个 constexpr 数组
- 如何将 char 类型数组传递给函数并将第一个字符数组复制到第二个图表数组并使用 c++ 进行比较