Hi,
Please see this:
When i make a declaration as:
char *i, j[15], *k;
and then do
sprintf( k, "print.sh %s", i );
the program works fine.
But when i change the declaration to:
char *i, *k;
and then do
sprintf( k, "print.sh %s", i );
I get a segmentation fault at the 'sprintf' statement.
The program works only when j is an array of 15. Nothing less/more
Please Note: variable j is just a dummy. I do absolutely nothing with it.
Also, i know using sprintf the way i have done is illegal. The pointer is not assigned to anything, prior to such a statement.
It may be silly
but could someone please explain why this happens? Guess something to do with the way memory is allocated.
Thanks in advance!