public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Error in "vfprintf"
       [not found] ` <d61b2f2205081519586ca2c730@mail.gmail.com>
@ 2005-08-16  3:10   ` Pavan G
  2005-08-16 17:31     ` Eljay Love-Jensen
  0 siblings, 1 reply; 2+ messages in thread
From: Pavan G @ 2005-08-16  3:10 UTC (permalink / raw)
  To: gcc-help-digest, gcc-help

On 8/15/05, Pavan G <aakashvani@gmail.com> wrote:
> On 8/15/05, Pavan G <aakashvani@gmail.com> wrote:
> > #include <stdio.h>
> > #include <math.h>
> > #include <string.h> 
> > #include <stdlib.h> 
> > #include <ctype.h>
> > struct cdnates
> > {float X,Y,Z;};
> > struct cdnates  pro[1960], gle[206][14];
> > FILE
> >
> *input,*input2,*input3,*input4,*outputs,*outputs1,*outputs2,*outputs3,*outputs4,*outputs5,*outputs6,*outputs7;
> > main()
> > {
> >   char w[10], w1[10], w2[10],ww[10];
> >   float xavg,yavg,zavg,dist1,dist2,x2,y2,z2;  
> >   int sh1=0,sh2=0,sh3=0,sh4=0,sh5=0,sh6=0,sh7=0,p0=0,g1=0,a,c=0,g0=0,
> m=20;
> >   double sqrt(double);
> > ...
> > ...
> > ....
> >      printf("%d %d %d %d %d %d %d
> > \t%4.1f\n",sh1,sh2,sh3,sh4,sh5,sh6,sh7,((double)m/10));
> >       fprintf(outputs1,"\t%4.1f\t %d\n",((double)m/10),sh1);
> >       //fprintf(outputs2,"\t%4.1f\t %d\n",((double)m/10),sh2);      
> >       //fprintf(outputs3,"\t%4.1f\t %d\n",((double)m/10),sh3);
> >       //fprintf(outputs4,"\t%4.1f\t %d\n",((double)m/10),sh4);
> >       //fprintf(outputs5,"\t%4.1f\t %d\n",((double)m/10),sh5);
> >       //fprintf(outputs6,"\t%4.1f\t %d\n",((double)m/10),sh6);
> >       //fprintf(outputs7,"\t%4.1f\t %d\n",((double)m/10),sh7);
> >     }
> >   return 0;
> > }
> > =================================================
> > Now, when I run the above program, I get a error (Segmentation fault
> > actually).
> > [root@head 20-80wt]# gdb she -q
> > (gdb) b main
> > Breakpoint 1 at 0x8048589: file allweight.c, line 21.
> > (gdb) r fff
> > Starting program: /home/pavan/amber/20-80wt/she fff
> > 
> > Breakpoint 1, main () at allweight.c:21
> > 21	  int sh1=0,sh2=0,sh3=0,sh4=0,sh5=0,sh6=0,sh7=0,p0=0,g1=0,a,c=0,g0=0,
> > m=20;
> > (gdb) b fprintf
> > Breakpoint 2 at 0x4205a178
> > (gdb) c
> > Continuing.
> > 37 15 20 60 42 32 0 	 0.1
> > 
> > Breakpoint 2, 0x4205a178 in fprintf ()
> >    from /lib/i686/libc.so.6
> > (gdb) c
> > Continuing.
> > 
> > Breakpoint 2, 0x4205a178 in fprintf ()
> >    from /lib/i686/libc.so.6
> > (gdb) c
> > Continuing.
> > 
> > Program received signal SIGSEGV, Segmentation fault.
> > 0x420502ea in vfprintf () from /lib/i686/libc.so.6
> > (gdb) c
> > Continuing.
> > 
> > Program terminated with signal SIGSEGV, Segmentation fault.
> > The program no longer exists.
> > (gdb) quit
> > =============================================
> > 
> > If you observe, the progran has a slew of "fprintf" prompts. The
> > segfault DOESNOT occur when I comment out all the fprintf's except the
> > first one or when I comment out all the fprintf's.
> > However, when I run the program with more than the first fprintf 
> > active, I see a segfault.
> > I'll be greatful if you could help me in this regard.
> > 
> > Pavan
> >
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Error in "vfprintf"
  2005-08-16  3:10   ` Error in "vfprintf" Pavan G
@ 2005-08-16 17:31     ` Eljay Love-Jensen
  0 siblings, 0 replies; 2+ messages in thread
From: Eljay Love-Jensen @ 2005-08-16 17:31 UTC (permalink / raw)
  To: Pavan G, gcc-help

Hi Pavan,

Put this in your code:

if(outputs1 == NULL) fprintf(stderr, "outputs1 is NULL\n");
if(outputs2 == NULL) fprintf(stderr, "outputs2 is NULL\n");
if(outputs3 == NULL) fprintf(stderr, "outputs3 is NULL\n");
if(outputs4 == NULL) fprintf(stderr, "outputs4 is NULL\n");
if(outputs5 == NULL) fprintf(stderr, "outputs5 is NULL\n");
if(outputs6 == NULL) fprintf(stderr, "outputs6 is NULL\n");
if(outputs7 == NULL) fprintf(stderr, "outputs7 is NULL\n");

Do these statements just before your:

fprintf(outputs1,"\t%4.1f\t %d\n",((double)m/10),sh1);

HTH,
--Eljay


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-08-16 17:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <d61b2f2205081519417b6d906@mail.gmail.com>
     [not found] ` <d61b2f2205081519586ca2c730@mail.gmail.com>
2005-08-16  3:10   ` Error in "vfprintf" Pavan G
2005-08-16 17:31     ` Eljay Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).