473,396 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 4247
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Anks | last post by:
i am unable to find why following code is giving segmentation fault.... way to produce seg fault: run the program... give input 12345678....enter any key except 'x'.... again give 12345678 as...
7
by: Adi | last post by:
hi guys, i have a weird problem with printf statement. I have a function which just prints a string literal. In my program this function will be called > 2000 times. I get a segmentation fault...
3
by: Zheng Da | last post by:
Program received signal SIGSEGV, Segmentation fault. 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 (gdb) bt #0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 #1 0x40094c54 in malloc...
5
by: Fra-it | last post by:
Hi everybody, I'm trying to make the following code running properly, but I can't get rid of the "SEGMENTATION FAULT" error message when executing. Reading some messages posted earlier, I...
27
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! ...
7
by: pycraze | last post by:
I would like to ask a question. How do one handle the exception due to Segmentation fault due to Python ? Our bit operations and arithmetic manipulations are written in C and to some of our...
3
by: madunix | last post by:
My Server is suffering bad lag (High Utlization) I am running on that server Oracle10g with apache_1.3.35/ php-4.4.2 Web visitors retrieve data from the web by php calls through oci cobnnection...
11
satyanagendra
by: satyanagendra | last post by:
hi I already write a database program in c and it is working fine. I change some modifications in the structure which holds the data in the database in that i got segmentation fault. the code is...
61
by: arnuld | last post by:
I have created a program which creates and renames files. I have described everything in comments. All I have is the cod-duplication. function like fopen, sprint and fwrite are being called again...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.