error: initializer fails to determine size of 'state'

Trying to generate a function to get a char array. Heres my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <string>
#include <sstream>
using namespace std;


char* getstate () {
    string state ("");
    cout << "Enter the State: ";
    cin >> state;
    string Georgia ("Georgia");
    string georgia ("georgia");
    string ga ("ga");
    string GA ("GA");
    string Ga ("Ga");
    bool state1 = state.compare(Georgia) == 0;
    bool state2 = state.compare(georgia) == 0;
    bool state3 = state.compare(ga) == 0;
    bool state4 = state.compare(GA) == 0;
    bool state5 = state.compare(Ga) == 0;

    if  ( state1 || state2 || state3 || state4 || state5 ) {
        char states[] = { 'G' , 'A' };
        return states;
    }
    else
    { cout << "Invalid Syntax, please start over.";
    }
}
char* concatestrings () {
    char state[] = getstate ();


at char state[] = getstate (); is where i'm getting the error "initializer fails to determine size of 'state'".

Very new to programming so I dont see why it can't determine its size.
state[] needs to have a constant between the brackets to determine the array's size. I recommend that you consider using strings ONLY.

-Albatross
Last edited on
If I use strings, how do I get it to return values of strings
Return an std::string instead of a char*.
Thank you both
Topic archived. No new replies allowed.