Sponsored Content
Top Forums Programming segmentation fault while returning from function. Post 302437392 by er.rohan88 on Thursday 15th of July 2010 02:06:52 AM
Old 07-15-2010
segmentation fault while returning from function.

I am working on the application in which I have to fetch values from the database and paste in url and send it to portal.

Code:
table=get_result("SELECT serialno,cas,Mode,FLC,TLC,location,CompName,CompCode,FG,FC,DispNo,TruckNo,LWbill,RRGPN,INVNO,DCN,RQTY,DQTY,SQTY,DDATE,RDATE,SDATE,TTIME FROM Drafts");

                   if(table.rows>1)
                                           
                    {//draft table opened               
                     
                     printf("\n Data in Drafts table...\n");
                                                            
                     for(i=0;i<table.rows;i++)
                                                                
                     {//outer loop
                                                                    
                         printf( " \t");
                                                                    
                         for(j=0;j<table.cols;j++)
                                                                        
                         {//inner loop 
                                                                    
                           printf("\n%d:%s",j,table.recordset[i][j]);  
                        
                         }//inner loop ends..
                        
                            choice=atoi(table.recordset[i][1]);//case

                            printf(" the choice is %d",choice);





switch(choice)
                            
{//Switch starts
                        
case 1:

sprintf(url,"http://%s:%s/FCMSBihar/Device/ReadData.aspx?Mode=%s&FLF=%s&FLC=%s&CC=%s&PPC=0&FG=%s&RRGPN=%s&LBillNo=%s&RQTY=%s&RDATE=%s%s&DDATE=%s",ipaddr,Port,table.recordset[i][2],table.recordset[i][5], table.recordset[i][3],table.recordset[i][7],table.recordset[i][9], table.recordset[i][10],table.recordset[i][13],table.recordset[i][16], table.recordset[i][20],table.recordset[i][22],table.recordset[i][19]);

printf("\nThe URL is %s",url);

                        GET_file_clear(url,"/mnt/jffs2/RP_rcpt.txt");//Launch the url to get the response.
                                                                                            
                        fp=fopen("/mnt/jffs2/RP_rcpt.txt","r");//Read response
                                                                
                        printf("\nthe file Contents are:");
                                                                
                        printf("Opening the file\n");
                                                                
                        while(fgets(buff_response,100,fp))    //buffer by buffer reading            
                                                                
                        {                        
                                                                  
                         printf("Reading the file\n");


                                                                
                        }

                        fclose(fp);

                        printf("\nthe response is: %s",buff_response);
                                                                
                        if(strstr(buff_response,"Successfull"))//checking the response.
                                                    
                            {//if successful clear the record from Drafts.

execute("DELETE FROM Drafts WHERE location ='%s'AND serialno='%s'AND Mode='%s';",table.recordset[i][5],table.recordset[i][0],table.recordset[i][2]);

                            sucess_count++;//increaments the success counter

                            }

                           else

                           {//if fails
                              
                              fail_count++;//increaments the fail counter

                            }

                        memset(url,'\0',sizeof(url));

                         break;

sprintf(str_sucess_report,"Record send is : %d",sucess_count);

sprintf(str_fail_report,"Record fail is : %d",fail_count);

printf("\n Records send is : %d ",sucess_count);//total successful transactions

printf("\n Records fail is : %d ",fail_count);//total failed transactions
                  
getchar();
free_result(table);
return 0;

In this code I had used the "table=get_result();" function in which I used to create database by giving the memory by malloc to rows and columns.
This whole process work well when i fetch 10to 11 records after that I creates the segmentation fault when I return after posting 30 to 40 data at the statement of "return 0 ".

please help me!!!!
 

10 More Discussions You Might Find Interesting

1. Programming

Why not a segmentation fault??

Hi, Why I don't receive a segmentation fault in the following sample. int main(void) { char buff; sprintf(buff,"Hello world"); printf("%s\n",buff); } If I define a buffer of 10 elements and I'm trying to put inside it twelve elements, Should I receive a sigsev... (22 Replies)
Discussion started by: lagigliaivan
22 Replies

2. UNIX for Dummies Questions & Answers

Segmentation Fault

Hi, While comparing primary key data of two tables thr bteq script I am getting this Error. This script is a shell script. *** Error: The following error was encountered on the output file. Script.sh: 3043492 Segmentation fault(coredump) Please let me know how to get through it. ... (5 Replies)
Discussion started by: monika
5 Replies

3. Programming

segmentation fault in fwrite function

Hi, my code is written in proC and it is in UNIX(AIX).I have written a small code for writing data into a binary file,but while writing my program is giving core dump. Here Is my code---- fpWriteFile = fopen(WriteFileName,"wb+"); CHAR *recvgen; recvgen = (char... (7 Replies)
Discussion started by: ajaysahoo
7 Replies

4. Programming

Segmentation fault.

I'm getting a segmentation fault. I'm new to Linux programming. Thanks so much for all of your input.:eek: #include </usr/include/mysql++/mysql++.h> #include <stdio.h> #include <iostream> #include <sstream> #include <string.h> using namespace std; int outputToImport(const char*... (1 Reply)
Discussion started by: sepoto
1 Replies

5. Programming

segmentation fault.

This code is causing a segmentation fault and I can't figure out why. I'm new to UNIX and I need to learn how to avoid this segmentation fault thing. Thank you so much. Thanks also for the great answers to my last post.:):b: int main() { mysqlpp::Connection conn(false); if... (3 Replies)
Discussion started by: sepoto
3 Replies

6. UNIX for Dummies Questions & Answers

Segmentation fault

#include<stdio.h> #include<malloc.h> #include<unistd.h> #include<stdlib.h> void *start_1(void *argv) { printf("thread 0x%x\n",(unsigned int)pthread_self()); pthread_exit((void*)1); } void *start_2(void *argv) { printf("thread 0x%x\n",(unsigned int)pthread_self()); return (void*)2; }... (2 Replies)
Discussion started by: vincent__tse
2 Replies

7. Programming

Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this : i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Discussion started by: pooyair
6 Replies

8. Shell Programming and Scripting

Segmentation fault in function call, shell script

I am getting Segmentation fault at below function call in my script: get_x() { sqlplus -s / <<end | grep KEEP | sed 's/KEEP//;s///g' select 'KEEP' ,table_name from all_synonyms where upper(synonym_name)= '$1'; exit end x=$(get_x $1) echo " SQL OUTPUT IS :: $x" } I am getting output of... (1 Reply)
Discussion started by: IB_88
1 Replies

9. Programming

Segmentation fault when I pass a char pointer to a function in C.

I am passing a char* to the function "reverse" and when I execute it with gdb I get: Program received signal SIGSEGV, Segmentation fault. 0x000000000040083b in reverse (s=0x400b2b "hello") at pointersExample.c:72 72 *q = *p; Attached is the source code. I do not understand why... (9 Replies)
Discussion started by: jose_spain
9 Replies

10. Programming

C. To segmentation fault or not to segmentation fault, that is the question.

Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1... I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one. Below are two very condensed snippets of which I have added the results inside the each code section. IMPORTANT!... (11 Replies)
Discussion started by: wisecracker
11 Replies
All times are GMT -4. The time now is 08:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy