I get a segmentation fault each time I'm trying to run this function.
char *hist_array[20];
int history_counter = 0;
void save_to_history(char *temp){
temp = malloc(512);/*512 is the size of temp array*/
printf("temp = %s\narray = %s",temp,hist_array[history_counter]);/*debug*/
strcpy(hist_array[history_counter],temp);
printf("Saved %s to history to %d\n\n",hist_array[history_counter],history_counter);
history_counter++;
}
I'm not sure whether I'm using malloc
correctly or not, but as I understand it should help with properly saving my string temp
to an array of strings hist_array
. Also, temp is never NULL
.
EDIT 1: Changed sizeof(temp) to its proper size 512, still getting segfault
.