Just trying to scan N
strings to an array and dynamically allocate them
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 3
#define MAX_STR_LEN 20
void main(void) {
char* str_arr[N] = { '\0' };
char temp_str[MAX_STR_LEN] = { '\0' };
for (size_t i = 0; i < N; i++)
{
//scan string
fgets(temp_str, MAX_STR_LEN, stdin);
strtok(temp_str, "\n");
// next line of code triggers breakpoint at second iteration
*(str_arr + i) = (char*)calloc((strlen(temp_str) + 1), sizeof(char));
if (!(str_arr + i))
{
printf("Could not allocate memory\n");
return 1;
}
//copy temporary string to dedicated string
strcpy_s(*(str_arr + i), sizeof(temp_str), temp_str);
}
printf("\n");
system("PAUSE");
}