--- In [email protected], "Brett McCoy" <[EMAIL PROTECTED]> wrote:
>
> On Feb 3, 2008 5:14 AM, Aswin Rajamannar <[EMAIL PROTECTED]> wrote:
> 
> > I'm new to C programming. While working with files,
> > they say we can open and read or edit files. I can't
> > understand the whole shit. What files can we open?
> > My friend says we can open  only text files lik .txt
> > and read it and add contents to it. But in a book, i
> > saw that we can open files with extension .c and work
> > with them. I don't just want to mug up what the text
> > book says and write it in exam and pass. Tell me what
> > a file pointer points to and what is the big advantage
> > working with files. At a moment, i thought of skipping
> > this section and proceed, but i feel you could prove
> > some help to me.
> 
> You can open ANY kind of file in C and C++, text or binary.
> To a C program, a file is just a stream of bytes and it's
> how the program intereprets the bytes that is important.
> Input/output operations are a pretty important aspect of
> programming (not just C), and if you can't use files, you
> will be losing an important set of skills for the future.
<snip>

I think one common miconception in such a place (it's not the first
time that I stumble upon such questions) is the "we". Who is "we"?

In the first place, "we" most often refers to the users and/or the
coders. To human beings, generally spoken. And human beings can only
read texts. Meaning that we (you, Thomas, Brett, CrazeeMom, myself,
and all the other people) can only read bunches of bytes ("files" in
the most general sense) if these bytes represent characters AND this
representation as strings of characters is presented to us (e.g. by a
text editor, Word, OpenOffice, Acrobat Reader, and the like). In this
sense it's correct to say that "we" human beings can only read text files.

In the second place, a computer program can (in principle) read and
write any sort of files. In fact any modern OS does that implicitly.
For example, executable files are files which can be loaded into RAM
and then be executed to perform some action. Such as email clients.

In the third place, "we" can mean: all programmers and all computers
on this planet which have been programmed by human programmers.

Now the point is: who can give a definition how every kind of file is
to be treated? The answer is: human beings have set up such
definitions; some in a smart manner, some in a less smart manner.

The most common way to define what to do with what sort of file is to
make this decision depend on the "type" of file to deal with. For
example, it's sort of common sense to say that a file named ".txt"
probably denotes a text file, so it makes sense that such a file be
opened and worked on by means of your favourite text editor.
On the other hand it's convention since the early 1970's that files
named ".c", ".cpp", ".h", or ".hpp" are files in either C or C++.
Meaning that these are special text files; these text files are
written such that a special computer program (the "compiler") can
interpret the text contained hereinwith and (with several quite
complex intermediate steps) construct executable files out of them. Or
at least so-called "object files" which finally can be made part of an
executable. [A very rough simplification.]

What your friend means is this:
We human beings actually can only read and write texts. Now "some" of
us (meaning: not all human beings) are smart enough (and have got the
mandatory education) to write specially formatted text files which
make sense to certain computer programs; very often these files are
then considered "source code files" for a compiler, compilation
control files to a compiler controller (such as a "makefile" for the
utility "make"), specially formatted initialisation files for whatever
application (such as .ini files for many Windows applications), and
the like.
Yet to a computer all these files are just bunches of bytes. That they
have a special meaning to us human beings doesn't concern a computer
at all. It's only that we human beings have written certain programs
(such as "make", compilers, and many more) which utilise these
distinctions of file types; watch out: these distinctions are given to
a computer by us, by human beings. Computers don't care at all about
the meaning of files for us; it's only the applications which we have
"taught" to apply such distinctions which make a computer react
differently to different sorts of files.

I hope this helps, even though it's first pretty theoretical and
second very long. Sorry for the length, but -more often than not- I
don't see a good way to explain such things shorter.

Regards,
Nico

Reply via email to