problem on strcat

Newbie Member
15Dec2007,00:18   #1
faizanh's Avatar
hello freinds,

i have small program as follows

char arr[30] = "someString";
strcat(arr,arr);
cout<<arr<<endl;

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
Go4Expert Founder
15Dec2007,12:18   #2
shabbir's Avatar
Moved to C-C++ forum.
Ambitious contributor
15Dec2007,13:14   #3
Salem's Avatar
> 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.