Re: [opensuse] Need help with using cruses in c program
El 10/03/11 11:49, Terry Eck escribió:
On 03/09/2011 09:58 PM, Cristian Rodríguez wrote:
You probably want to install ncurses-devel and run
gcc `ncursesw6-config --cflags` account.c `ncursesw6-config --libs` ...
HTH.
Please tell me more about what is after ... I was able to compile account.c but not get a Segmentation Fault when the program is run. This has not happened in the past. Thanks for any ideas/help Terry
If it crashes, there might be an incompatibility, install gdb, compile the program #gdb yourprogram (gdb) run (gdb) bt full post your result to the list. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 03/10/2011 11:59 AM, Cristian Rodríguez wrote:
the program
#gdb yourprogram (gdb) run (gdb) bt full
post your result to the list.
I added writes to the program. This is the output: eck@linux-ihxk:/data/DATA/source/account> ./account level 0 level 1 level 2 level 2.1 level 2.1a 74 Segmentation fault ================================ using "gdb account" results in: eck@linux-ihxk:/data/DATA/source/account> gdb account GNU gdb (GDB) SUSE (7.1-3.12) Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i586-suse-linux". For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/... Reading symbols from /data/DATA/source/account/account...done. (gdb) run Starting program: /data/DATA/source/account/account Missing separate debuginfo for /lib/ld-linux.so.2 Try: zypper install -C "debuginfo(build-id)=fbaee3f5e15417f014dc59b0561eb7192ff04c5c" Missing separate debuginfo for /lib/libncurses.so.5 Try: zypper install -C "debuginfo(build-id)=5e4ad4b8f6d215dbb540ba5858512cdfea758f7e" Missing separate debuginfo for /lib/libc.so.6 Try: zypper install -C "debuginfo(build-id)=694c111567b7c83a6f1b97bb28f6687dbd0d3057" Missing separate debuginfo for /lib/libdl.so.2 Try: zypper install -C "debuginfo(build-id)=580696b460256b20961976ebf3b100e5a4c03c10" level 0 level 1 level 2 level 2.1 level 2.1a 74 Program received signal SIGSEGV, Segmentation fault. 0xb7e50158 in vfprintf () from /lib/libc.so.6 (gdb) The following is a segment of the code with problems. Appears to have a problem with fprintf. /* ------------------------------------------------------------------ */ put_sort() /* ------------------------------------------------------------------ */ { puts("level 2.1"); fi = fopen("account.srt", "w+"); puts("level 2.1a"); printf("%d\r\n",max_record); fprintf(fi,"%d\r\n",max_record); puts("level 2.1b"); i=1; while (i <= 16) ... Hope someone can make sense of this. Thanks for any help, Terry -- openSUSE 11.3 -- Kernel 2.6.34 -- GNU/Linux -- Thu 03/10/11 16:30pm up 5 days 0:38, 3 users, load average: 0.03, 0.05, 0.03 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
El 10/03/11 19:32, Terry Eck escribió:
On 03/10/2011 11:59 AM, Cristian Rodríguez wrote:
the program
#gdb yourprogram (gdb) run (gdb) bt full
post your result to the list.
I added writes to the program. This is the output:
level 0 level 1 level 2 level 2.1 level 2.1a 74
Program received signal SIGSEGV, Segmentation fault. 0xb7e50158 in vfprintf () from /lib/libc.so.6 (gdb)
The following is a segment of the code with problems. Appears to have a problem with fprintf.
/* ------------------------------------------------------------------ */ put_sort() /* ------------------------------------------------------------------ */ { puts("level 2.1"); fi = fopen("account.srt", "w+"); puts("level 2.1a"); printf("%d\r\n",max_record); fprintf(fi,"%d\r\n",max_record); puts("level 2.1b"); i=1; while (i <= 16)
ok, in case you are pointing to the right code, this crashes. "fprintf(fi,"%d\r\n",max_record);" is "fi" a valid file pointer... ? put after fi = fopen("account.srt", "w+"); if(fi == NULL) perror("Error WTF!"); Looks like there is some lazy-ass code there, there is no error checking whatsoever... ;-) and just seeing the firsts bits Im afraid it doesnt quite do what you expect.. HTH. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 03/10/2011 05:32 PM, Terry Eck wrote:
On 03/10/2011 11:59 AM, Cristian Rodríguez wrote:
the program
#gdb yourprogram (gdb) run (gdb) bt full
post your result to the list.
I added writes to the program. This is the output:
eck@linux-ihxk:/data/DATA/source/account> ./account level 0 level 1 level 2 level 2.1 level 2.1a 74 Segmentation fault ================================
using "gdb account" results in:
eck@linux-ihxk:/data/DATA/source/account> gdb account GNU gdb (GDB) SUSE (7.1-3.12) Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i586-suse-linux". For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/... Reading symbols from /data/DATA/source/account/account...done. (gdb) run Starting program: /data/DATA/source/account/account Missing separate debuginfo for /lib/ld-linux.so.2 Try: zypper install -C "debuginfo(build-id)=fbaee3f5e15417f014dc59b0561eb7192ff04c5c" Missing separate debuginfo for /lib/libncurses.so.5 Try: zypper install -C "debuginfo(build-id)=5e4ad4b8f6d215dbb540ba5858512cdfea758f7e" Missing separate debuginfo for /lib/libc.so.6 Try: zypper install -C "debuginfo(build-id)=694c111567b7c83a6f1b97bb28f6687dbd0d3057" Missing separate debuginfo for /lib/libdl.so.2 Try: zypper install -C "debuginfo(build-id)=580696b460256b20961976ebf3b100e5a4c03c10" level 0 level 1 level 2 level 2.1 level 2.1a 74
Program received signal SIGSEGV, Segmentation fault. 0xb7e50158 in vfprintf () from /lib/libc.so.6 (gdb)
The following is a segment of the code with problems. Appears to have a problem with fprintf.
/* ------------------------------------------------------------------ */ put_sort() /* ------------------------------------------------------------------ */ { puts("level 2.1"); fi = fopen("account.srt", "w+"); puts("level 2.1a"); printf("%d\r\n",max_record); fprintf(fi,"%d\r\n",max_record); puts("level 2.1b"); i=1; while (i <= 16) ...
You are not checking that "fi" is valid, i.e. that fopen succeeded. Until proven otherwise my first guess would be that fopen fails. Therefore, fi is NULL and fprintf has a problem with that, which is perfectly OK. Also there is no declaration for "max_record" some evil global int? Robert -- Robert Schweikert MAY THE SOURCE BE WITH YOU Novell-IBM Software Integration Center LINUX Tech Lead rschweikert@novell.com rschweikert@ca.ibm.com 781-464-8147 Novell Making IT Work As One -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
El 10/03/11 19:32, Terry Eck escribió:
On 03/10/2011 11:59 AM, Cristian Rodríguez wrote:
the program
#gdb yourprogram (gdb) run (gdb) bt full
post your result to the list.
Also compile with gcc -Wall $(rpm --eval %optflags) `ncursesw6-config --cflags` account.c `ncursesw6-config --libs` and show what warnings the compiler throws.. that may provide extra evidence. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 03/10/2011 04:46 PM, Cristian Rodríguez wrote:
ok, in case you are pointing to the right code, this crashes.
"fprintf(fi,"%d\r\n",max_record);"
is "fi" a valid file pointer... ? put after
fi = fopen("account.srt", "w+");
if(fi == NULL) perror("Error WTF!");
Looks like there is some lazy-ass code there, there is no error checking whatsoever... ;-) and just seeing the firsts bits Im afraid it doesnt quite do what you expect..
HTH.
The lazy-ass code is mine. I don't clam to be a "good" c programer. The code fragment is only a part of the program and "max-record" is defined (thanks for you input Robert you nailed it, the file was not opened). I finally found the problem with hints from both you and Robert. Thanks again, Terry -- openSUSE 11.3 -- Kernel 2.6.34 -- GNU/Linux -- Thu 03/10/11 19:15pm up 5 days 3:23, 3 users, load average: 0.01, 0.04, 0.01 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
El 10/03/11 22:24, Terry Eck escribió:
I don't clam to be a "good" c programer.
neither I do ;) in fact I currently believe there is no such person either :-D just regular C programmers that have learnt how to walk over landmines without blowing themselves up. Good that you found the problem. Cheers. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (3)
-
Cristian Rodríguez
-
Robert Schweikert
-
Terry Eck