so I'm trying to read a string back from a binary file that I've created,however, I'm unable to do so, I tried reading the string character by character, as well as a whole but none of these two worked, here's my code
int charge_Index(int Index[],int num)
{
char name[100];
nom_fich_Index(num,name);//generates the name of the file
FILE *f = fopen(name,"rb+");
int i=0,j=0;
char num[max_char];
if(f!=NULL)
{
fseek(f,0,SEEK_SET);
while(!feof(f))
{
j = 0;
strcpy(num,"");
while(j<10)
{
fread(&num[j],sizeof(char),1,f);
j = j+1;
}
num[11] = '\0';
Index[i] = atoi(num);
i = i + 1;
}
fclose(f);
}
else
{
printf("error when opening the file \n");
exit(1);
}
return i;
}
I was also wondering if it is necessary when writing a string in a binary file to add a null terminator?