Array of structs access violation

I'm new to C++, though I've programmed in scripting languages like PHP and Perl. I've got a very simple piece of code, that I actually got from a tutorial, that I just cannot get to work.

It compiles, but throws an access violation whenever I try to read from the struct:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
struct TileType {
	char displayChar;
	short colorCode;
	bool passable;
};

TileType tile[] = {
	{ '.', 7,  true },
	{ '#', 7,  false},
	{ '+', 6,  false }
};

int main() {
	char x = tile[0].displayChar;
	printf("%s", x); // access violation
	return 0;
}


Can anyone tell me what's going on? It's a global variable, so it should exist in main(), right? I think I must be fundamentally misunderstanding something, but the above code came from, like I said, a tutorial on C++, and I've been searching all day and can't figure it out.
The only problem I see is you are using %s on printf which implies you are passing in a string, however you are passing in "char x".

Change it to printf("%c", x); and it should work correctly.
Oh wow, did I overthink that one. You're right. /embarassed.

Thanks so much for the quick reply.
Topic archived. No new replies allowed.