On 11/02/2011 02:11 PM, Cristian Rodríguez wrote:
On 02/11/11 15:33, David C. Rankin wrote:
So where is this segfault coming from?
gdb --args ./a.out 1 2 3 4
Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7a88b03 in ____strtod_l_internal () from /lib64/libc.so.6 (gdb) bt full #0 0x00007ffff7a88b03 in ____strtod_l_internal () from /lib64/libc.so.6 No symbol table info available. #1 0x00000000004006d1 in main (argc=5, argv=0x7fffffffda78) at dcr.c:19 p = 0x7fffffffdf72 "" i = 5 rad = 4 area = 50.26548245743669 (gdb) frame 1 #1 0x00000000004006d1 in main (argc=5, argv=0x7fffffffda78) at dcr.c:19 19 rad = strtod(argv[i],&p); (gdb) p argv[i] $1 = 0x0 --> that's why ! argv[argc] is a null pointer!
bug is
for (i=1;i<= argc;i++) { ^^ should be< argc
Thank you Christian! I would have looked at this for days and not caught the '<=' issue. Aye, yie, yie, what possessed me to do that is beyond me, but I can assure you that once I did it, it would have taken an act of congress to make me see the error in my ways! Thanks again! 18:46 alchemy:~/dev/prg/ccpp/src-c/misc> gcc -Wall ztst.c -o ztst 18:46 alchemy:~/dev/prg/ccpp/src-c/misc> ./ztst 2 4 6 8 10 rad : 2.00 area : 12.5664 rad : 4.00 area : 50.2655 rad : 6.00 area : 113.0973 rad : 8.00 area : 201.0619 rad : 10.00 area : 314.1593 -- David C. Rankin, J.D.,P.E. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org