Stringy Issues of char* and Unions

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
union scenenames
{

	char names20[20];
	char names19[19];
	char names18[18];
	char names17[17];
	char names16[16];
	char names15[15];
	char names14[14];
	char names13[13];
	char names12[12];
	char names11[11];
	char names10[10];
	char names9[9];
	char names8[8];

};

struct scene
{

	int objectsy[25][25];

};

struct scene reader(struct scene direct, char filen[], int length, int height)
{

	int tab0;
	int tab1;
	int position = 1;
	int data0;
	int data1;

	for(tab1 = 0;tab1 < height;tab1++)
	{

		for(tab0 = 0;tab0 < length;tab0++)
		{

			data0 = readfile(filen, position); //Reads specified  character in specified file
			switch(data0)
			{

				case(10):
					tab0--;
					break;
				default:
					direct.objectsy[tab1][tab0] = data0;

			}
			position++;

		}

	}
	return direct;

}

int main()
{

union scenenames naming;

struct scene cmdintro;
naming.names13 = 'c','m','d','i','n','t','r','o','.','t','x','t','\0';
cmdintro = reader(cmdintro, naming.names13, 20, 12);

return 0;
}


The above code works great, except for the string and char stuff. How exactly do I define a string of varying length, and set it as an argument for the reader function? If I say;

cmdintro = reader(cmdintro, "cmdintro.txt", 20, 12);

It gives a "Deprecated conversion from string constant to char*" error. How do I fix these problems?

Also the reason I am using a union with so many chars of varying length is so I can define a char, enter it into the reader function, and define a new char of different length and enter it into the reader function while taking up minimal memory space.
Last edited on
Topic archived. No new replies allowed.