On Mon 2008-12-08 19:38:49 UTC-0000, mikejd42 ([EMAIL PROTECTED]) wrote:
> This segfaults.
>
> main( argc, argv )
> int argc;
> char *argv[];
> {
>
> func( "hello","this","is","a test" );
> }
>
> func( argv )
> char *argv[];
> {
>
> printf( "argv[0] = %s\n", argv[0] );
>
> }
You seriously need to stop writing K&R style. It will bite you.
Also, compile your programs with ALL warnings enabled.
$gcc -W -Wall -o a a.c
a.c:2: warning: return type defaults to int'
a.c: In function main':
a.c:6: warning: implicit declaration of function func'
a.c: At top level:
a.c:2: warning: unused parameter 'argc'
a.c:3: warning: unused parameter 'argv'
a.c: In function main':
a.c:7: warning: control reaches end of non-void function
a.c: At top level:
a.c:10: warning: return type defaults to int'
a.c: In function func':
a.c:13: warning: implicit declaration of function printf'
a.c:15: warning: control reaches end of non-void function
Look at all those warnings from gcc! Good code should produce no
warnings.
Among other MAJOR problems, you are passing four arguments to func()
when it only accepts one.