I am having a problem while trying to print to txt file from global array of char*.
My array is declared as
char* codes[256];
also i have a function that construct a string and returns it to after which that value is placed into this global array
char* printArr(int arr[], int n)
{
char* code = (char *) malloc(sizeof(char) * (n+1));
int i;
for (i = 0; i < n; ++i)
{
code[i] = arr[i] + '0';
}
code[n] = '\0';
return code;
}
after which I just simply place that value into that global array. After that I am trying to print that array values into a txt file like this :
void PrintToFile(char* outputFileName)
{
FILE* f = fopen(outputFileName, "w+");
int i;
for (i = 0; i < 256; ++i)
{
//printf("%s\n", codes[i]);
fprintf(f, "%s\n", codes[i]);
}
fclose(f);
}
But for some reason my txt file turns out blank. Also without opened stream when I try to print to stdout i get those values but with both printf and fprintf I don't get anything out either on stdout or in txt file.
Thanks in advance!