So I have a structure called fastarray which contains a poiner to another structure called token_det. My problem is trying to fill a char array inside the array of structs fails mid way through and gives a error message as "The exception unknown software exception (0x0000417) occured in the application at location 0x78b2ae6e". I tried increasing the size of the char array using malloc but the string concat function keeps failing after concatinating a few strings. Below is a example of the code:
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <iostream.h>
using namespace std;
#define MAX_TOKENS 300000
struct token_det
{
int token;
std::string data;
char mdepth[300];
};
typedef struct fastarray
{
token_det *td; //MAX_TOKENS
}FASTARRAY;
int main()
{
printf("inside main\n");
int lv_ret = 0;
int count = 0;
char log[50] = {""};
int wtoken = 0;
FASTARRAY *f_array = NULL;
f_array = (FASTARRAY *)malloc(sizeof(FASTARRAY));
f_array->td = NULL;
f_array->td = (token_det *)malloc(MAX_TOKENS * sizeof(token_det));
printf("after malloc\n");
memset(f_array, 0, sizeof(f_array));
memset(f_array->td, 0, sizeof(f_array->td));
int x=0;
while(x<=10000)
{
printf("inside while");
f_array->td[x].data = "104,";
f_array->td[x].data.append("stasimorphy");
f_array->td[x].data.append(",");
f_array->td[x].data.append("psychognosy");
f_array->td[x].data.append(",");
f_array->td[x].data.append("whoever");
f_array->td[x].data.append(",");
x++;
sprintf_s(log,sizeof(log),"Data for x-%d = %s\n",x,f_array->td[x].data);
printf(log);
}
free(f_array->td);
free(f_array);
printf("after while\n");
return 0;
}