problem on strcat

faizanh's Avatar, Join Date: Dec 2007
Newbie Member
hello freinds,

i have small program as follows

char arr[30] = "someString";

when i try to print arr nothing gets printed.
Strcat fn should append the string nothing gets appended .

please correct if iam wrong some where
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Moved to C-C++ forum.
Salem's Avatar, Join Date: Nov 2007
Ambitious contributor
> strcat(arr,arr);
There are very few standard C functions (memmove being a notable exception) which work reliably when the input and output buffers overlap. In essence, if you change the thing you're reading from, then expect surprises (sometimes the surprise comes years later).

This for example is likely to just keep going until it runs off the end of memory (or trashes something) and then it crashes.

Since you used cout, why not use std::string for all your strings. It's much safer.