LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-11-2012, 05:23 AM   #1
gauravdev
LQ Newbie
 
Registered: Oct 2012
Posts: 1

Rep: Reputation: Disabled
Getting segmentation fault(core dump) error


i am executing a program.it compiles properly but during the execution it gives segmentation fault error.code is

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<malloc.h>
#include <sqlca.h>
char *userid= "";
char *password= "";
struct cardTab
{
int slot_id;
char *itemcode;
};
void main()
{
FILE *f;
struct cardTab *cardTab_detail;
int card_id;
sql_context ctx;
cardTab_detail=(struct cardTab*)malloc(sizeof(struct cardTab));
printf("enter the card id");
scanf("%d",&card_id);
EXEC SQL CONTEXT ALLOCATE :ctx;
EXEC SQL CONTEXT USE :ctx;
EXEC SQL CONNECT :userid IDENTIFIED BY assword;
EXEC SQL
SELECT SLOT_ID,ITEM_CODE
INTO :cardTab_detail->slot_id, :cardTab_detail->itemcode
FROM CARD
WHERE
CARD_ID = :card_id;
EXEC SQL COMMIT;
f=fopen("store.txt" , "w");
fprintf(f,"%s \n", "this is my first program in Pro *C");
fprintf(f,"Slot Id = %d\n", cardTab_detail->slot_id);
fprintf(f,"Item Code = %s\n",cardTab_detail->itemcode);
fclose(f);
}

Thanks in Advance................
 
Old 10-12-2012, 03:44 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,121

Rep: Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270
how did you compile, how did you execute it?
 
Old 10-12-2012, 03:48 AM   #3
segmentation_fault
Member
 
Registered: Sep 2008
Location: Ioannina, Greece
Distribution: Gentoo
Posts: 332

Rep: Reputation: 55
On a quick look you are copying some data to cardTab_detail->itemcode which is a pointer to char. Unless what you are trying to copy there is a char * that operation will cause issues. Compile your program with debuging symbols and no opitmizations (that means "-g -O0" gcc options) and run it with gdb. when it segfaults run backtrace. That should give you some more insight.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
segmentation fault(core dump) error with mobiwan simz Linux - Networking 1 04-25-2012 07:37 AM
segmentation fault (core dump) bhatia.ankur8 Linux - General 1 07-06-2010 05:58 AM
segmentation fault core dump shaiva Linux - Newbie 1 09-23-2009 12:04 PM
how to force a core-dump...segmentation fault johnpaulodonnell Programming 2 10-23-2008 07:05 AM
php core dump with segmentation fault ohcarol *BSD 9 10-14-2008 10:19 AM


All times are GMT -5. The time now is 12:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration