Could you please help me? I got a segmentation fault message while
trying to assign a pointer = pointer like this:
bufferlist[i]=(buffer_t*)buf fernew;
What's the error by doing this? Here is the full C script of what I
did. I would be really really appreciate your help. I need to finish
this code by monday but i'm stuck at this point and can't solve it :-(
Thank you very much
-------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define K 5
#define Kprime 7
#define N 10
#define MAX_PACKETSIZE 1000
#define BUFFER_SIZE 20
typedef struct _buffer {
int packetid; /**< the parameter key **/
int** decodetab; /**< the parameter value **/
int counter;
} buffer_t;
typedef struct _packet {
int* data;
int id;
} packet_t;
buffer_t* selectbuffer(bu ffer_t** bufferlist,int id,int packetsize){
int i;
buffer_t* buffernew;
i=0;
while(bufferlis t[i]!=NULL){
i=i+1;
if(i>=BUFFER_SI ZE){
printf("element not found & buffer overflow");
break;}
if(bufferlist[i]->packetid==id ){
return bufferlist[i];
}
}
//when element not found, we will add new buffer at the end of this
bufferlist
if(id<Kprime){
buffernew=(buff er_t*)malloc(si zeof(buffer_t)) ;
buffernew->counter=0;
buffernew->packetid=id;
bufferlist[i]=(buffer_t*)buf fernew; <************** ********** the
error come from this line
}
}
int main(){
packet_t* pk;
buffer_t* buffer;
buffer_t** bufferlist;
int packetsize;
packetsize=10;
pk = malloc(sizeof(p acket_t));
pk->id=3;
bufferlist = malloc(sizeof(b uffer_t*)*BUFFE R_SIZE);
buffer = selectbuffer(bu fferlist,pk->id,packetsize) ;
buffer = selectbuffer(bu fferlist,pk->id,packetsize) ;
}
trying to assign a pointer = pointer like this:
bufferlist[i]=(buffer_t*)buf fernew;
What's the error by doing this? Here is the full C script of what I
did. I would be really really appreciate your help. I need to finish
this code by monday but i'm stuck at this point and can't solve it :-(
Thank you very much
-------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define K 5
#define Kprime 7
#define N 10
#define MAX_PACKETSIZE 1000
#define BUFFER_SIZE 20
typedef struct _buffer {
int packetid; /**< the parameter key **/
int** decodetab; /**< the parameter value **/
int counter;
} buffer_t;
typedef struct _packet {
int* data;
int id;
} packet_t;
buffer_t* selectbuffer(bu ffer_t** bufferlist,int id,int packetsize){
int i;
buffer_t* buffernew;
i=0;
while(bufferlis t[i]!=NULL){
i=i+1;
if(i>=BUFFER_SI ZE){
printf("element not found & buffer overflow");
break;}
if(bufferlist[i]->packetid==id ){
return bufferlist[i];
}
}
//when element not found, we will add new buffer at the end of this
bufferlist
if(id<Kprime){
buffernew=(buff er_t*)malloc(si zeof(buffer_t)) ;
buffernew->counter=0;
buffernew->packetid=id;
bufferlist[i]=(buffer_t*)buf fernew; <************** ********** the
error come from this line
}
}
int main(){
packet_t* pk;
buffer_t* buffer;
buffer_t** bufferlist;
int packetsize;
packetsize=10;
pk = malloc(sizeof(p acket_t));
pk->id=3;
bufferlist = malloc(sizeof(b uffer_t*)*BUFFE R_SIZE);
buffer = selectbuffer(bu fferlist,pk->id,packetsize) ;
buffer = selectbuffer(bu fferlist,pk->id,packetsize) ;
}
Comment