Segmentation fault while transferring data to a Berkeley-DB?

Up vote 0 down vote favorite share g+ share fb share tw.

Below is my code: When I try to send a value to a Berkeley DB, I am getting segmentation fault. It seems there is some problem in which I am putting the values inside the database. Any kind of suggestions would be helpful.

#include #include #include #include #include #include #include "unistd. H" #include #include #define MAXPROFILES 2 #include #define DATABASE "access. Db" float Pearson(int mySum, int recSum, int multSum); int main(int argc, char *argv) { int sockfd, newsockfd, portno, clilen; struct sockaddr_in serv_addr, cli_addr; unsigned char buf1024; int index1=0; // char* pointer = buf; struct profile_t { unsigned char length; unsigned char type; unsigned char *data; }; typedef struct profile_datagram_t { unsigned char *src; unsigned char *dst; unsigned char ver; unsigned char n; struct profile_t profilesMAXPROFILES; } header; struct pearson_record{ unsigned char *src; }; struct pearson_record s; DB *dbp; DBT key, data; int ret, t_ret; if ((ret = db_create(&dbp, NULL, 0))!

= 0) { fprintf(stderr, "db_create: %s\n", db_strerror(ret)); exit (1); } if ((ret = dbp->open(dbp, NULL, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664))! = 0) { dbp->err(dbp, ret, "%s", DATABASE); goto err; } header outObj; int j =0; int I =0; if (argc 0){ index1 = my_datai; myDataBinaryindex1 = 1; //printf("my data %d = %d\n",index1,myDataBinaryindex1); } } for (int j=0; j 0){ index1 = outObj.profilesi. Dataj; recDataindex1 = 1; //printf("rec data %d = %d\n",index1,recDataindex1); } } for(int i=0;iput(dbp, NULL, &key, &data, 0)) == 0) printf("db: %s: key stored.

\n", (char *)key. Data); else { dbp->err(dbp, ret, "DB->put"); goto err; } if ((ret = dbp->get(dbp, NULL, &key, &data, 0)) == 0) printf("db: %s: key retrieved: data was %s. \n", (char *)key.

Data, (char *)data. Data); else { dbp->err(dbp, ret, "DB->get"); goto err; } err: if ((t_ret = dbp->close(dbp, 0))! = 0 && ret == 0) ret = t_ret; } return 0; } float Pearson(int mySum, int recSum, int multSum) { float Cov =0; float sdMyData = 0; float sdRecievedData =0; float rho; int n = 500; Cov = (1.0/(n-1))*(multSum - (1.0/n)*mySum*recSum); sdMyData = sqrt((1.0/(n-1))*(mySum - (1.0/n)*mySum*mySum)); sdRecievedData = sqrt((1.0/(n-1))*(recSum - (1.0/n)*recSum*recSum)); printf("\nCovariance = %f, \nVarianceMyData = %f, \nVarianceRecData = %f",Cov,sdMyData,sdRecievedData); if (sdMyData == 0.0 || sdRecievedData == 0.0){ rho = 0.0; }else{ rho = Cov/(sdMyData*sdRecievedData); } return(rho); } c berkeley-db structures link|improve this question edited Aug 25 '11 at 3:06 asked Aug 25 '11 at 3:00user5376701617 36% accept rate.

2 Please indent your code properly. – Dhaivat Pandya Aug 25 '11 at 3:03 @Dhaivat: I am new to C, I have problems in indentation and all, especially while posting questions. – user537670 Aug 25 '11 at 3:28 You should learn to use gdb, and run your code in a debugger: it will be MUCH faster at pointing out where exactly you are going wrong.

Take a look at sourceware.org/gdb/current/onlinedocs/gdb – Femi Aug 25 '11 at 3:36 Compile with -ggdb option and run with valgrind : valgrind --tool=memcheck – vine'th Aug 25 '11 at 4:21.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions