const char* to char

I am making a simple decision-based program. I am using Dev-C++, and I am using a data structure. However, when I end the list of items it gives me an error saying "invalid conversion from 'const char*' to 'char'".

example of the structure:

typedef void (*____type) ();
struct ____struct {char name; ____type ____;};
____struct _ [6] = {
{"blank", &blank1},
{"blank", &blank2},
{"blank", &blank3},
{"blank", &blank4},
{"blank", &blank5},
{"blank", &blank6}};

It gives me an error for the last line, and I don't know what is wrong because I have other structures in there with the same format, and I don't get any errors for those...

Can anyone offer me any help? I don't know how to fix this....

Thanks!
Last edited on
You're trying to initialize a character with a character array, that makes no sense.
And what's with all the underscores? Is this an entry for some obfuscation contest?
"blank" is not a char which is a single character, but a const char[] which is an array of characters.

Simple solution, use C++ strings:
1
2
3
4
5
6
7
8
9
10
11
#include <string>

typedef void (*____type) ();
struct ____struct {std::string name; ____type ____;};
____struct _ [6] = {
{"blank", &blank1},
{"blank", &blank2},
{"blank", &blank3},
{"blank", &blank4},
{"blank", &blank5},
{"blank", &blank6}};


Disclaimer: didn't test to see if it works or not.
1. Sorry, the underscores were what the inputs were, as well as the blanks

This is what a section of the code looks like:

1
2
3
4
5
6
7
8
9
10
typedef void (*maptype) ();
struct placestruct {char name [30]; maptype map;};
placestruct p [8] = {
{"Valley", &map1},
{"Castle Courtyard", &map2},
{"Castle Market", &map21},
{"Castle Library", &map22},
{"Throne Room", &map23},
{"Forest of Trials", &map3},
{"Town", &map5}};


The string didn't quite work...it is now me the error message:

cannot convert 'const char*' to 'void(*)()' in initialization


I may just have to try something different if I can't fix the problem...
Last edited on
Topic archived. No new replies allowed.