0

I have no idea why it doesn't work. What is more I can't even say what are errors about ;/ Can any1 explain what are errors about?

The code is suposed to : create a string with word like - mom. then create 2d array to fill it by string. Free spaces fill with _.So mom box =

[m] [o]

[m] [_]

now fill next array with text that follows from colums. mom_ filled to new array will look like mmo_. Then I cout crypted text. I hope u understood whatI did there :D

here is code

//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];
        }
    }
}
1
  • You're mixing C++ with C. C++ doesn't have VLAs. Commented Mar 16, 2013 at 20:54

1 Answer 1

2

d[x][y] has no meaning in tab d is a single dimension array. You will have to pass the first dimension as argument and use it when indexing. Something like:

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];
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.