Invalid conversion from "const char*" to "char"

Hey Guys!

I just tried a little classes and object stuff and came over an error which I can't really figure out - mybe I'm too tired already or just not experienced enough.

The problem occurs when I want to pass over the adress of a char array pointer to another pointer due the return value of a function.


1
2
3
4
5
6
7
  void Screen_output::player_create()
 {
	char * array = file_to_array();
	
	*(array+900) = "X";
	field();
 }


It's all about that one.

I gonna post the rest of the header file so you can see what function is returning that adress. Actually I didn't set the return value to a const char* just a char* - that's why I'm a bit confused why my compiler throws this error.

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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <fstream>
#include <string>

#ifndef Screen_output_h   
#define Screen_output_h  

using namespace std;

class Screen_output
{
	const char * field_name;
	public:
	void create_field(const char*);
	void title(const char*);
	void field();
	char * file_to_array();
	void player_create();

} draw;

 void Screen_output::player_create()
 {
	char * array = file_to_array();
	
	*(array+900) = "X";
	field();
 }

void Screen_output::create_field(const char* file_n)
{
	field_name = file_n;
}
	
void Screen_output::title(const char* file_n)			
{
	string text_line;
	
	ifstream file (file_n);
		if (file.is_open()) 
		{
			while(getline(file, text_line))
			{
			cout << text_line << endl;	
			}
			file.close();
		}
}

void Screen_output::field()
{
	string text_line;
	
	ifstream file (field_name);
		if (file.is_open()) 
		{
			while(getline(file, text_line))
			{
			cout << text_line << endl;
			}
			file.close();
		}
}

char * Screen_output::file_to_array()
{	
	int array_size = 1799;
	char * array = new char[array_size];
	int position = 0;


	ifstream file (field_name);
		if (file.is_open()) 
		{
			while(!file.eof())
			{
				file.get(array[position]);
				position++;
			}
			file.close();
		}
	
	return array;
		
	// for(int i = 0; i < position-1; i++)
	// {
		// cout << array[i];
	// }
}

#endif  



Error Message:

1
2
3
4
8 C:\Users\Charlie\Desktop\KI Project 2.0\main.cpp In file included from main.cpp
 C:\Users\Charlie\Desktop\KI Project 2.0\Screen_output.h In member function `void Screen_output::player_create()': 
26 C:\Users\Charlie\Desktop\KI Project 2.0\Screen_output.h invalid conversion from `const char*' to `char' 
 C:\Users\Charlie\Desktop\KI Project 2.0\Makefile.win [Build Error]  [main.o] Error 1  
Last edited on
"X" is a string (const char*). It has two characters: 'X' and '\0'.

'X' is a character.

Change:
*(array+900) = "X";
to
*(array+900) = 'X';
Topic archived. No new replies allowed.