Barry said:
santosh said:
The following code is giving run-time error.....
char buf[100] = "Hello" ;
strcat(buf,buf) ;
Second line is giving the run-time error.
Any comments please............
When you use strcat, you are obligated to insure that the area from
which data is being extracted does not overlap the area into which
data is being deposited. Your code invokes undefined behavior. Be
thankful it resulted in an error as opposed to something pernicious.
The way to avoid errors with strcpy and strcat is to not use them.
There is a (non-standard for now) replacement set called strlcpy
and strlcat, which do intelligent things and return intelligent
information. They came out of the FreeBSD operation, I believe.
At any rate an implementation in standard C, with suitable
references, is readily available at:
<
http://cbfalconer.home.att.net/download/strlcpy.zip>
--
"The power of the Executive to cast a man into prison without
formulating any charge known to the law, and particularly to
deny him the judgement of his peers, is in the highest degree
odious and is the foundation of all totalitarian government
whether Nazi or Communist." -- W. Churchill, Nov 21, 1943