470,573 Members | 1,653 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,573 developers. It's quick & easy.

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
Jun 27 '08 #1
3 3866
"vasu_7...@yahoo.com" <vasu_7...@yahoo.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
Jun 27 '08 #2
In article <a3**********************************@y38g2000hsy. googlegroups.com>,
va*******@yahoo.com <va*******@yahoo.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)
Jun 27 '08 #3
On Jun 4, 4:52*am, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote:
In article <a3daa8bd-7fd0-476a-87ab-84de1974e...@y38g2000hsy.googlegroups.com>,

vasu_7...@yahoo.com <vasu_7...@yahoo.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
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Anks | last post: by
7 posts views Thread by Adi | last post: by
5 posts views Thread by Fra-it | last post: by
27 posts views Thread by Paminu | last post: by
7 posts views Thread by pycraze | last post: by
3 posts views Thread by madunix | last post: by
satyanagendra
11 posts views Thread by satyanagendra | last post: by
61 posts views Thread by arnuld | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.