• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

is there any way to write only the chars in an array and not the terminating /0?

Onceler

Golden Member
I want to write to disk the chars from an array as if they had all been mad as individual chars(not part of an array). Is this possible?
 
You don't need to save the terminating null character to disk. And you can write characters one at a time if you want. The sky's the limit. Post some code if you want a better response.
 
Using the functions discussed in your other posts it should just be a matter of either not copying the terminating null to the output buffer, or setting the number of bytes to be written so that the last character is ignored. There's nothing special about an array of char in C, which is in fact why the terminating null is necessary.
 
Did you read my response in your other thread about writing files?
http://forums.anandtech.com/showthread.php?t=2305989

with a function like fwrite you pass it an address and the number of bytes to write. If the string is all single-byte / ASCII characters then the number of bytes is the string length.

But: if it is a variable-length string, how are you going to read it back in later without the 0-terminator?

Say you have 2 strings "hello" and "goodbye". If you use a serialization function it would include the \0 so the file looks like this:

h e l l o \0 g o o d b y e \0

And code to de-serialize can read up to the \0.

If you used fwrite, the file looks like this:

h e l l o g o o d b y e

And a de-serialization function might return "hellogoodbye" the first time you try to read a string.

That's not a problem if all strings are fixed-length, then you can fread using that length and (if needed) add a \0 at [ legnth ] in your array.
 
Last edited:
Did you read my response in your other thread about writing files?
http://forums.anandtech.com/showthread.php?t=2305989

with a function like fwrite you pass it an address and the number of bytes to write. If the string is all single-byte / ASCII characters then the number of bytes is the string length.

But: if it is a variable-length string, how are you going to read it back in later without the 0-terminator?

Say you have 2 strings "hello" and "goodbye". If you use a serialization function it would include the \0 so the file looks like this:

h e l l o \0 g o o d b y e \0

And code to de-serialize can read up to the \0.

If you used fwrite, the file looks like this:

h e l l o g o o d b y e

And a de-serialization function might return "hellogoodbye" the first time you try to read a string.

That's not a problem if all strings are fixed-length, then you can fread using that length and (if needed) add a \0 at [ legnth ] in your array.
No I had not read that, something appears to be wrong with my subscriptions-I seem not to be getting notified when someone posts.
Thank you all of you.
 
No I had not read that, something appears to be wrong with my subscriptions-I seem not to be getting notified when someone posts.
Would it be easier for you, if you could collect all your I/O-related questions into one thread instead of multiple, somewhat redundant ones?

Have you got/found documentation for the I/O-functions (fread, fwrite, ...)?
 
Back
Top