how to store and read bynary string

Hello!

In text-file storing we write
1
2
fscanf(fp1, "%s ", str);
fprintf(fp2, "%s ", str);

to read and write a string from and to a file...

now, think fp a pointer to a bynary data. the writing should be:

 
fwrite(str, sizeof(char), strlen(str), fp);


but, what should I do to read the string from the bynary file??
I don't know the string lenght in reading process so I cannot tell the third parameter of the fread() function...

should I store even the string lenght?

thanks
You can avoid storing the length if it is null terminated ;)
so obvious that I didn't think to it! thanks :)
Topic archived. No new replies allowed.