functional error

Ok, So I'm working on an all in one Chemistry calculator. spare me on the logistics of how hard this is of a task. That aside. I've some problems getting the file IO to work right

this the code I'm working with, Now mind you I know using the fstream would be easier, but I need to know how to do this so I can backwards engineer for reading integer values from a file. Plus I dont know how to create a file with fstream.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ifstream elemental_list;
FILE * c_file;

void create(const char c_elmf[256], string c_elm)
{

	c_file = fopen(c_elmf[256], "w");
	if(c_file == NULL)
	{
		cout << "file error";
	} 
	else 
	{element new_element;
	
	new_element.symbol = c_elm; 
	fputs (c_elm, c_file);
	}
}


Now I compile the main program that this is called from, and i get this error
error: invalid conversion from `const char' to `const char*'
error: initializing argument 1 of `FILE* fopen(const char*,const char*)


anyone know a solution?

Last edited on
The array you have defined is actually just a const char* to the first address in disguise. So for fopen, just pass c_elmf as the first parameter and it should work. When you have the [256] on the end, that secretly dereferences the pointer and passes the char at that location.
ah thanks :D
Topic archived. No new replies allowed.