char *ReadFile(string& filepath)
{
	string buffer="";
	char temp_char;
	ifstream file;
	file.open(filepath);
	while(!(file.eof()))
	{
		file.get(temp_char);
		buffer+=temp_char;
	}
	size=buffer.length();
	char *result1=new char[size];
	for(int i=0;i<buffer.length();i++)
	{
		result1[i]=buffer[i];
	}
	file.close();
	return result1;
}

code looks pretty normal right?
but when I run it with the rest of the program this happens...
http://imageshack.us/photo/my-images/267/chararray0001.jpg/
http://imageshack.us/photo/my-images/28/chararray0002.jpg/
http://imageshack.us/photo/my-images/11/chararray0003.jpg/
on the declaration of my result1 array(line 13) some string appends to it from the end and even if I enter values in the array it shifts and sticks to my array and when I return it it returns with the stupid meaningless string...
any ideas?
if you want the whole code I can paste here... there is no result1 declared before...
there is not much happening before function is called. some cout and cin lines only...

Edited 4 Years Ago by fastali: n/a

well I need a char array as a result to use it on other functions... I wrote it already its too much of a pain to change... I will try null terminating it might probably solve my problem but I still dont get what that string is and it bugs me... :/ thx for the advice...

thx for the advice but I converted it myself I aint gonna bother with it anymore... I failed to remember that the char arrays needed to be null terminated... I'm a bit new to C++ I have been codding in C# before so it sometimes becomes confusing... thanx for your help pal...

This question has already been answered. Start a new discussion instead.