Segmentation Fault at fwrite... Help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vasu_7799@yahoo.com

    Segmentation Fault at fwrite... Help

    Hi,
    I have 2 structure.

    struct a
    {
    char cn[14+1];
    char tl[5+1];
    char roup[3+1];
    char rc[6+1];
    char adj[13+1];
    char qty[13+1];
    char cr[1];
    } abrec;


    EXEC SQL BEGIN DECLARE SECTION;
    struct a_data
    {
    char cn[14];
    char tl[5];
    char roup[3];
    char rc[6];
    char adj[13];
    char qty[13];
    } abdata;
    EXEC SQL END DECLARE SECTION;

    There is a function getting data from database and write into the
    file. A few lines from this function,

    ::::::
    memcpy ( abrec.adj, abdata.adj, 13);
    memcpy ( abrec.cr, "\n", 1);

    Then, I have

    if ( fwrite ( &abrec, sizeof(abrec), 1, fp1 ) != 1 )
    {
    fprintf ( stderr, "ERROR: Could not write cob_adjd_rec!
    \n" );
    fflush(stderr);
    exit(-1);
    }

    Here, fwrite is giving me segmentation fault. More details (using
    debugger)

    (dbx) run
    Running: pm
    (process id 11523)
    t@1 (l@1) signal SEGV (no mapping at the fault address) in fwrite at
    0xfe613e88
    0xfe613e88: fwrite+0x0018: ld [%i3 + 12], %o1
    Current function is write_ub92_cob_ adjd_rec
    2986 if ( fwrite ( &abrec, sizeof(abrec), 1, fp1 ) != 1 )
    (dbx)

    Can anyone help me with this.....???? Please

    Thank you
    vasu
  • Peter Nilsson

    #2
    Re: Segmentation Fault at fwrite... Help

    "vasu_7...@yaho o.com" <vasu_7...@yaho o.comwrote:
    Hi,
       I have 2 structure.
    Did you mean you have _a_ structure?
    >
    struct a
    {
        char    cn[14+1];
        char    tl[5+1];
        char    roup[3+1];
        char    rc[6+1];
        char    adj[13+1];
        char    qty[13+1];
        char    cr[1];
    } abrec;
    >
    EXEC SQL BEGIN DECLARE SECTION;
         struct a_data
         {
            char    cn[14];
            char    tl[5];
            char    roup[3];
            char    rc[6];
            char    adj[13];
            char    qty[13];
         } abdata;
    EXEC SQL END DECLARE SECTION;
    Please don't post implementation specific extensions.
    If your question isn't about the C language, take it
    to a group that specialises in the extensions you're
    using.
    There is a function getting data from database and
    write into the file. A few lines from this function,
    >
       memcpy ( abrec.adj, abdata.adj, 13);
       memcpy ( abrec.cr, "\n", 1);
    >
    Then, I have
    >
       if ( fwrite ( &abrec, sizeof(abrec), 1, fp1 ) != 1 )
        {
           fprintf ( stderr, "ERROR:  Could not write cob_adjd_rec!
    \n" );
           fflush(stderr);
           exit(-1);
        }
    >
    Here, fwrite is giving me segmentation fault.
    Please post a compilable snippet that exhibits the problem.
    The most obvious guess at the moment is that fp1 is not
    a pointer to a valid file stream.

    --
    Peter

    Comment

    • Richard Tobin

      #3
      Re: Segmentation Fault at fwrite... Help

      In article <a3daa8bd-7fd0-476a-87ab-84de1974e314@y3 8g2000hsy.googl egroups.com>,
      vasu_7799@yahoo .com <vasu_7799@yaho o.comwrote:
      >t@1 (l@1) signal SEGV (no mapping at the fault address) in fwrite at
      >0xfe613e88
      >0xfe613e88: fwrite+0x0018: ld [%i3 + 12], %o1
      >Current function is write_ub92_cob_ adjd_rec
      2986 if ( fwrite ( &abrec, sizeof(abrec), 1, fp1 ) != 1 )
      fp1 is probably not an open file. Did you check the return value of
      fopen()?

      -- Richard
      --
      In the selection of the two characters immediately succeeding the numeral 9,
      consideration shall be given to their replacement by the graphics 10 and 11 to
      facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)

      Comment

      • vasu_7799@yahoo.com

        #4
        Re: Segmentation Fault at fwrite... Help

        On Jun 4, 4:52 am, rich...@cogsci. ed.ac.uk (Richard Tobin) wrote:
        In article <a3daa8bd-7fd0-476a-87ab-84de1974e...@y3 8g2000hsy.googl egroups.com>,
        >
        vasu_7...@yahoo .com <vasu_7...@yaho o.comwrote:
        t@1 (l@1) signal SEGV (no mapping at the fault address) in fwrite at
        0xfe613e88
        0xfe613e88: fwrite+0x0018:      ld       [%i3 + 12], %o1
        Current function is write_ub92_cob_ adjd_rec
        2986       if ( fwrite ( &abrec, sizeof(abrec), 1, fp1 ) != 1 )
        >
        fp1 is probably not an open file.  Did you check the return value of
        fopen()?
        >
        -- Richard
        --
        In the selection of the two characters immediately succeeding the numeral 9,
        consideration shall be given to their replacement by the graphics 10 and 11 to
        facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)
        I have got this. Actually, problem with the file permissions.

        Thank you,
        vasu

        Comment

        Working...