Weird behaviour of strcat()..

int send(const char * ftp, const char * user, const char * pass, const char * pathondisk, char * nameonftp)
	char * buf=nameonftp;
	cout<<pathondisk<<endl;//Here i get the correct output
	cout<<pathondisk<<endl;//but here i get only one single character

I have only pasted code that was causing problem, would you please tell me how this can happen? is there anything wrong the way i am using strcat(). Its weird because the 'pathondisk' is a const char and even though i applied strcat() on another string the contents of 'pathondisk' are altered.
Last edited on
Using strcat *modifies* the string. So when you get past line 5, nameonftp now has extra characters in it. I doubt that was what you intended.

You could probably avoid all this by just using std::string.
I intended to add ".txt" to nameonftp that was stored to "buf", everything fine there but how come the contents of pathondisk changed?
thats what i am asking..
thanks for replying
Well you aren't actually. You are making buf point to the same thing nameonftp points to, so when you modify buf, you are also modifying nameonftp.

If nameonftp isn't big enough to hold the extra characters, it will keep writing off into other address space, which might include some of pathondisk's characters, which is why it was modified.
Thanks alot firedraco, problem solved.
Topic archived. No new replies allowed.