char *ReadFile(string& filepath)
	string buffer="";
	char temp_char;
	ifstream file;;
	char *result1=new char[size];
	for(int i=0;i<buffer.length();i++)
	return result1;

code looks pretty normal right?
but when I run it with the rest of the program this happens...
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...

Recommended Answers

All 4 Replies

Why don't you just return std::string instead of char* ? Also you need to null terminate result1.

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...

You do know that std::string has a function that returns constant char pointer. check it out

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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.