I have a struct:
typedef struct _test{
int a;
int b;
int c;
float f_arr[16384];
}test_t;
that struct i need to write in csv format into a file. I thought i might use a snprintf function to put everything into one char buffer, but: i need to convert each value from f_arr:
char f_t_str[30];
char arr[16384*2][30];
for (i=0; i< 16384; i++){
sprintf(f_t_str, "%.8f" ,test_t->f_arr[i]);
memcpy(arr[i*2], f_t_str, strlen(f_t_str));
printf("%s\n",arr[i*2]);
arr[i*2 + 1][0] = ',';
}
so, if i now have my float array converted to one big string in arr, i can just make a:
char dest[16384*2 + 512];
snprintf(dest, 16384*2 + 512, "%d,%d,%d,%s", test_t->a, test_t->b, test_t->s, arr);
but as a result im having:
10,11,12,13.1
instead of:
10,11,12,13.1,13.2,14.4.... [16384] ... 16400.23
i suppose that during conversion from float to char sprintf adds '\0' at end of string, so next snprintf (the one after loop is finished) finishes after it meets that '\0' - first value from 'arr'. How to make it working ?
regards J.