On Thu, 18 Feb 1999, Anubhav Hanjura wrote:
# main()
# {
#
# char *filename;
# char *string =3D "this is a string";
#
# strcpy(filename,string);
# printf("filename is %s\n",filename);
# }
This _should_ break. where does *filename point?
from the strcpy() man page:
DESCRIPTION
The strcpy() function copies the string pointed to be src
(including the terminating `\0' character) to the array
pointed to by dest. The strings may not overlap, and the
destination string dest must be large enough to receive
the copy.
key part: the destination string must be large enough.... since *filename
is undefined then chances are you'll attempt to write to memory you don't
own and cause a SIGSEGV (segmentation fault), there is a small chance you
will access memory you do own and that is why it doesn't always break.
first make *filename point somewhere by using malloc() or turning it into
an array...
--
+++ Beware of programmers who carry screwdrivers +++
[EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit