string word;
    cout << "type in the word you want to be decrypted >> ";
    cin >> word;
    char dword[] = word;

this does't work, is it because yo can't use the line

char dword[] = word;

if it is because of that then please tell me what i have to do to make it work, if it isn't because of that then please tell me what it is.

there is more code to this program, but it's just this part that isn't working.

the error messages i receive are:
initializer fails to determine size of `dword'
invalid initializer

This is an invalid line of code:

char dword[] = word;

What were you trying to achieve?

well this is the whole code, ait's supposed to be a substitution cipher solver, and it works fine if replace the "word" variable with some letters.

#include <iostream>
#include <string.h>

using namespace std;

int main()
{
    string word;
    cout << "type in the word you want to be decrypted >> ";
    cin >> word;
    char dword[] = word;
    bool KeepOn(true);
    do {
    int a = 0;
    int p = 0;
    int t = 1;
    while(dword[a]){
                    if(dword[a]=='a'){
                                      dword[a] = 122-p;
                                      cout << (char)dword[a];
                                      ++p;
                                      goto after;
                                      }
                    if(dword[a]!='a'){
                     dword[a] = (int)dword[a]-t;
                     cout << (char)dword[a];
                     }
                     after:
                     ++a;
                     }
    string answ;
    cout << "\nIs this your solution? >> ";
    cin >> answ;
    if(answ == "yes"){
            cout << "\nwell there you have it";
            KeepOn = true;
            cin.get();
            cin.get();
            }
    if(answ == "no") {
               cout << "let's try again" << endl;
               KeepOn = false;
               ++t;
               }
    }while(!KeepOn);
}

All what I need to know is: what do you expect this instruction to do: char dword[] = word; ?

All what I need to know is: what do you expect this instruction to do: char dword[] = word; ?

well i want it to have the same function as if i had written

dword[]="Loveyou";

like if I enter yuck inte the word string then
dword[0] =y
dword[1] =u
dword[2] =c
dword[3] =k
dword[4] =0

the thing is that a program like this works

char streng[]="array"
int i = 0;
while(streng[i]){
cout << streng[i] << "=" << (int)streng[i];
++i;
}

i want the same thing to happen just that "array" could be any word, a variable

The fact is, you can't just do that, it's impossible, once you write: char streng[]= then you'll have to follow it by a string (something between double quotes), otherwise the compiler doesn't know how many bytes he has to reserve for the character array.

If you want to copy the contents of a C++ string inside a C string, then you can't just use the assignment operator (=), if this is what you want to do, then you should take a look at the link in my previous post.

Why do you want an array? The string class will work for both sides of the encryption:

int main()
{
    string word, dword;

    // read a word

    for (string::size_type x = 0; x < word.length(); ++x)
    {
        dword += Crypt(word);
    }

    cout << word << '\n' << dword << '\n';
}

The fact is, you can't just do that, it's impossible, once you write: char streng[]= then you'll have to follow it by a string (something between double quotes), otherwise the compiler doesn't know how many bytes he has to reserve for the character array.

If you want to copy the contents of a C++ string inside a C string, then you can't just use the assignment operator (=), if this is what you want to do, then you should take a look at the link in my previous post.

well thank you for taking time, and yes that is what I'm trying to do so I'll just have to find an other way do it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.