C with variable -length and ram question....

U

uche

Hello all! I have thought about this question for a long time and I
would like to know your opinion about it: In C, a variable-length
string can be carried in RAM as a sequence of ASCII characters
followed by a NULL character. Would this work in a disk field? What
are some considerations to be aware of?
 
M

Malcolm McLean

uche said:
Hello all! I have thought about this question for a long time and I
would like to know your opinion about it: In C, a variable-length
string can be carried in RAM as a sequence of ASCII characters
followed by a NULL character. Would this work in a disk field? What
are some considerations to be aware of?
"What are some considerations to be aware of?" is not normal English.

It is professorese.

Your attempt to have homework done is detected and flagged.
 
J

J. J. Farrell

Hello all! I have thought about this question for a long time and I
would like to know your opinion about it: In C, a variable-length
string can be carried in RAM as a sequence of ASCII characters
followed by a NULL character. Would this work in a disk field? What
are some considerations to be aware of?

What is a "disk field"? I have a storage pool outside my office
window, but I've never seen a disk field.
 
C

CBFalconer

J. J. Farrell said:
What is a "disk field"? I have a storage pool outside my office
window, but I've never seen a disk field.

wheat grows in wheat fields
corn grows in corn fields
hay grows in hay fields
poppies grow in poppy fields
disks grow in disk fields.

QED. See Wordsworth for daffodil fields.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
 
R

Richard Tobin

CBFalconer said:
wheat grows in wheat fields
corn grows in corn fields
hay grows in hay fields
poppies grow in poppy fields
disks grow in disk fields.

Magnets produce magnetic fields, electricity produces electric fields, ...

-- Richard
 
S

santosh

uche said:
Hello all! I have thought about this question for a long time and I
would like to know your opinion about it: In C, a variable-length
string can be carried in RAM as a sequence of ASCII characters
followed by a NULL character.

In C, there's no such thing as a "variable length" string, as opposed
to fixed length string. The C standard does not specify a particular
character set, like ASCII, and it doesn't define RAM.
Would this work in a disk field? What
are some considerations to be aware of?

Yes strings can be written to a disk file, and read back in with
fprintf and fscanf among other functions.
 
K

Keith Thompson

santosh said:
In C, there's no such thing as a "variable length" string, as opposed
to fixed length string. The C standard does not specify a particular
character set, like ASCII, and it doesn't define RAM.


Yes strings can be written to a disk file, and read back in with
fprintf and fscanf among other functions.

At the risk of doing part of the OP's homework, text written to a file
is typically in the form of lines (terminated by '\n'), not strings
(terminated by '\0').
 
R

Richard Heathfield

Keith Thompson said:
At the risk of doing part of the OP's homework, text written to a file
is typically in the form of lines (terminated by '\n'), not strings
(terminated by '\0').

Of course, writing '\0' into a file will work just fine (but I wouldn't
suggest using a text file if you're going to do that).
 
J

Joe Wright

uche said:
Hello all! I have thought about this question for a long time and I
would like to know your opinion about it: In C, a variable-length
string can be carried in RAM as a sequence of ASCII characters
followed by a NULL character. Would this work in a disk field? What
are some considerations to be aware of?
Just to keep things clear, NULL is a pointer constant, not a character.
The character is often referred to as NUL or '\0' or simply 0.

The string is an array of char ending with (and including) '\0'. The
string is a memory thing. The analogous stream (file) thing is a line. A
line is a series of bytes ending with (and including) '\n', a newline.

I (and others) consider text files with '\0' characters to be corrupted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top