Search code examples
c++voiddeclare

I cannot seem to find the appropriate way to declare char a[] and char b[]


#include <iostream>

using namespace::std;

int main(){

void dost(char a[],  char b[]);    
void man(void);

{
    char s1[] = "TBTBABLJ";
    char s2[] = "IBSVOB";
    dost(s1, s2);
    cout << s2 << endl;
}
void dost(char a[],  char b[]);
{
    b[3] = b[1];    b[2] = a[4]; b[0] = a[0];   
}
}

How would I declare a and b in the correct scope without a size error? I tried declaring them under main, but that just gave more errors, and under void dost didn't seem to work either. I'm pretty new to this so any help would be appreciated!


Solution

  • You have braces and semicolons in the wrong place. The proper layout for this code could be:

    #include <iostream>
    
    using namespace std;
    
    void dost(char a[],  char b[]);    
    
    int main()
    {
        char s1[] = "TBTBABLJ";
        char s2[] = "IBSVOB";
        dost(s1, s2);
        cout << s2 << endl;
    }
    
    void dost(char a[],  char b[])
    {
        b[3] = b[1];
        b[2] = a[4]; 
        b[0] = a[0];   
    }
    

    Then there are no errors and the program should run correctly.

    I would recommend using consistent code indentation. If you see } followed by } in the same column on the next line, as you had at the end of your original code, that suggests there is a mistake with brace placement that you can look into fixing.