I have a pointer to my struct gsa_sentence
which has a struct member of type char*
called untouched_sentence
.
My goal is to copy a line from a file, into this struct variable using strcpy, but I am getting a segmentation fault on the strcpy function call.
structure:
typedef struct gsa_sentence{
char *untouched_sentence;
char *sentence_id;
char mode;
int fix;
int sv_1;
int sv_2;
int sv_3;
int sv_4;
int sv_5;
int sv_6;
int sv_7;
int sv_8;
int sv_9;
int sv_10;
int sv_11;
int sv_12;
int pdop;
int hdop;
int vdop;
}gsa_sentence;
strcpy call:
gsa_sentence* gsa;
gsa = malloc(sizeof(gsa_sentence));
printf("%s", line);
if(gsa != NULL){
strncpy(gsa->untouched_sentence, line, strlen(line));
printf("%s", gsa->untouched_sentence);
}
I have used strcpy elsewhere in my code and it works fine, I cannot figure out what is going on.
The gdb debugger says it's definately on the strcpy function call