Data Files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Xarky

    #1

    Data Files

    Hi,
    Is it possible to make use of data files in C? If yes can someone
    tell how or suggest me a site from where I can learn them.


    Thanks in Advance for your patience.
  • Richard Bos

    #2
    Re: Data Files

    bernardpace@yah oo.com (Xarky) wrote:
    [color=blue]
    > Is it possible to make use of data files in C?[/color]

    No, it's not. Data files are a very advanced subject of information
    theory, much too complicated for a simple language like C. In fact, even
    C++, which we all know is a much stronger language than C, capable of
    expressing much more advanced data types, is barely strong enough to
    handle data files.
    If you really need to use C, stick to simple kinds of files like binary
    and text files, and keep all your data in memory or on the stack. If you
    do need to use data files, my suggestion is to use a truly modern,
    advanced programming language, such as ADA, ML, or Visual Basic.

    Richard

    Comment

    • Thomas Matthews

      #3
      Re: Data Files

      Richard Bos wrote:[color=blue]
      > bernardpace@yah oo.com (Xarky) wrote:
      >
      >[color=green]
      >> Is it possible to make use of data files in C?[/color]
      >
      >
      > No, it's not. Data files are a very advanced subject of information
      > theory, much too complicated for a simple language like C. In fact, even
      > C++, which we all know is a much stronger language than C, capable of
      > expressing much more advanced data types, is barely strong enough to
      > handle data files.
      > If you really need to use C, stick to simple kinds of files like binary
      > and text files, and keep all your data in memory or on the stack. If you
      > do need to use data files, my suggestion is to use a truly modern,
      > advanced programming language, such as ADA, ML, or Visual Basic.
      >
      > Richard[/color]

      Either there is sarcasm in this reply, or we have a different
      understanding of the term "data file".

      My understanding is any "data", integers, text, whatever, that
      is placed into a file makes the file a "data file". That file
      could be as simple as a word list or as complex as a database.

      According to my definition, any language that has file access
      capabilities can make use of data files.

      The OP should review the "Files" or "I/O" section of a good
      C language reference manual.


      --
      Thomas Matthews

      C++ newsgroup welcome message:

      C++ Faq: http://www.parashift.com/c++-faq-lite
      C Faq: http://www.eskimo.com/~scs/c-faq/top.html
      alt.comp.lang.l earn.c-c++ faq:

      Other sites:
      http://www.josuttis.com -- C++ STL Library book

      Comment

      • Darrell Grainger

        #4
        Re: Data Files

        On Mon, 3 May 2004, Xarky wrote:
        [color=blue]
        > Hi,
        > Is it possible to make use of data files in C? If yes can someone
        > tell how or suggest me a site from where I can learn them.[/color]

        The question is too vague to answer. I'd be inclined to say the answer is
        YES. To the second part of your question, get a good text book on C
        language or take a class at your local school. I have yet to see a good
        online tutorial for someone with no programming experience.

        --
        Send e-mail to: darrell at cs dot toronto dot edu
        Don't send e-mail to vice.president@ whitehouse.gov

        Comment

        • Richard Bos

          #5
          Re: Data Files

          Thomas Matthews <Thomas_Matthew sSpitsOnSpamBot s@sbcglobal.net > wrote:
          [color=blue]
          > Richard Bos wrote:[color=green]
          > > bernardpace@yah oo.com (Xarky) wrote:
          > >[color=darkred]
          > >> Is it possible to make use of data files in C?[/color]
          > >
          > > No, it's not. Data files are a very advanced subject of information
          > > theory, much too complicated for a simple language like C.[/color]
          >
          > Either there is sarcasm in this reply,[/color]

          Surely not! Me, sarcastic? Inconceivable!

          Richard

          Comment

          • Allan Bruce

            #6
            Re: Data Files


            "Xarky" <bernardpace@ya hoo.com> wrote in message
            news:bc42e1a.04 05030307.13847a 60@posting.goog le.com...[color=blue]
            > Hi,
            > Is it possible to make use of data files in C? If yes can someone
            > tell how or suggest me a site from where I can learn them.
            >
            >
            > Thanks in Advance for your patience.[/color]

            why wouldnt it be possible? What kind of data are you talking about. I use
            C and store vertex/texture data of 3d models usinf fwrite, and load them
            back using fread. No problems, nice and quick and fairly darned reliable.
            Perhaps, you should re-word your question?
            Allan


            Comment

            • Karthik

              #7
              Re: Data Files

              Xarky wrote:
              [color=blue]
              > Hi,
              > Is it possible to make use of data files in C?[/color]

              I am afraid that is a very generic question. Having said that, there
              is one thing you would like to know to begin with files in C - there are
              text and binary data files and you distinguish between them while trying
              to open the file.
              Now, any standard C book should have something related to FILE
              manipulation and the FILE data structure associated with this, that can
              answer your questions.

              [color=blue]
              > If yes can someone
              > tell how or suggest me a site from where I can learn them.[/color]
              There is only one site for all the fundamental questions -
              http://www.google.com .

              --
              Karthik
              Humans please 'removeme_' for my real email.

              Comment

              • CBFalconer

                #8
                Re: Data Files

                Richard Bos wrote:[color=blue]
                > bernardpace@yah oo.com (Xarky) wrote:
                >[color=green]
                > > Is it possible to make use of data files in C?[/color]
                >
                > No, it's not. Data files are a very advanced subject of information
                > theory, much too complicated for a simple language like C. In fact,
                > even C++, which we all know is a much stronger language than C,
                > capable of expressing much more advanced data types, is barely
                > strong enough to handle data files.
                >
                > If you really need to use C, stick to simple kinds of files like
                > binary and text files, and keep all your data in memory or on the
                > stack. If you do need to use data files, my suggestion is to use a
                > truly modern, advanced programming language, such as ADA, ML, or
                > Visual Basic.[/color]

                Very amusing. You might have borne in mind that you are replying
                to some sort of newbie, who is quite likely to take you
                seriously. A sarcasm wrapper, or even some smileys, would have
                been appropriate.

                --
                A: Because it fouls the order in which people normally read text.
                Q: Why is top-posting such a bad thing?
                A: Top-posting.
                Q: What is the most annoying thing on usenet and in e-mail?


                Comment

                • Malcolm

                  #9
                  Re: Data Files


                  "Xarky" <bernardpace@ya hoo.com> wrote in message[color=blue]
                  >
                  > Is it possible to make use of data files in C? If yes can someone
                  > tell how or suggest me a site from where I can learn them.
                  >[/color]
                  I suspect you are using the term "data files" to refer to some sort of
                  specific file format, such as a commercially available database might use.

                  In ANSI C you can open a file in text mode or in binary mode using the
                  fopen() function. You then have to know the format of the file to interpret
                  the data, which might be an ASCII text file, a JPEG image, a sound file, or
                  practically anything.

                  Now if someone has defined a special file format they will very often
                  provide C functions to help to parse it. For instance, if you are using MS
                  Windows, you can load a bitmap using a function that Microsoft has provided.
                  This will be one call rather than having to do all the work yourself. If
                  your "data file" is provided by a third party, then it is extremely likely
                  that they will have written some functions in C and will provide them to
                  programmers (assuming that they offer suport to developers at all).


                  Comment

                  • Joona I Palaste

                    #10
                    Re: Data Files

                    Richard Bos <rlb@hoekstra-uitgeverij.nl> scribbled the following:[color=blue]
                    > Thomas Matthews <Thomas_Matthew sSpitsOnSpamBot s@sbcglobal.net > wrote:[color=green]
                    >> Richard Bos wrote:[color=darkred]
                    >> > bernardpace@yah oo.com (Xarky) wrote:
                    >> >> Is it possible to make use of data files in C?
                    >> >
                    >> > No, it's not. Data files are a very advanced subject of information
                    >> > theory, much too complicated for a simple language like C.[/color]
                    >>
                    >> Either there is sarcasm in this reply,[/color][/color]
                    [color=blue]
                    > Surely not! Me, sarcastic? Inconceivable![/color]

                    "You keep using that word. I don't think it means what you think it
                    means."
                    Did I do this right? Anyway, I think that "The Holy Grail" is a much
                    funnier movie.

                    --
                    /-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
                    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
                    "Show me a good mouser and I'll show you a cat with bad breath."
                    - Garfield

                    Comment

                    • Stephen Sprunk

                      #11
                      Re: Data Files

                      "Xarky" <bernardpace@ya hoo.com> wrote in message
                      news:bc42e1a.04 05030307.13847a 60@posting.goog le.com...[color=blue]
                      > Is it possible to make use of data files in C? If yes can someone
                      > tell how or suggest me a site from where I can learn them.[/color]

                      Of course you can. Open a file, read or write some data, close the file.

                      Asking a more specific question will likely get you a more useful answer.

                      S

                      --
                      Stephen Sprunk "Stupid people surround themselves with smart
                      CCIE #3723 people. Smart people surround themselves with
                      K5SSS smart people who disagree with them." --Aaron Sorkin

                      Comment

                      • Xarky

                        #12
                        Re: Data Files

                        bernardpace@yah oo.com (Xarky) wrote in message news:<bc42e1a.0 405030307.13847 a60@posting.goo gle.com>...[color=blue]
                        > Hi,
                        > Is it possible to make use of data files in C? If yes can someone
                        > tell how or suggest me a site from where I can learn them.
                        >
                        >
                        > Thanks in Advance for your patience.[/color]

                        ***
                        Hi,

                        First of all, sorry for all the inconvenience made due me to not
                        being clear in my query.

                        In my file I need to store the following (mainly for a small
                        database):
                        int position;
                        char *data;
                        int check;

                        Also I have to add the data mentioned at EOF or sometimes randomly
                        at any position in the file, or delete at any position. Can this be
                        done.

                        Can someone tell me how to do this in a simple way (if there is).

                        I hope it is more clear now the meaning of data files.


                        Thanks in Advance

                        Comment

                        • Richard Bos

                          #13
                          Re: Data Files

                          CBFalconer <cbfalconer@yah oo.com> wrote:
                          [color=blue]
                          > Richard Bos wrote:[color=green]
                          > > If you really need to use C, stick to simple kinds of files like
                          > > binary and text files, and keep all your data in memory or on the
                          > > stack. If you do need to use data files, my suggestion is to use a
                          > > truly modern, advanced programming language, such as ADA, ML, or
                          > > Visual Basic.[/color]
                          >
                          > Very amusing. You might have borne in mind that you are replying
                          > to some sort of newbie, who is quite likely to take you
                          > seriously.[/color]

                          Pah. Anyone who cannot spot the sarcasm in someone calling Visual Basic
                          and ML "modern, advanced programming languages", and those two in the
                          same breath, is not awake enough to be programming in C.

                          Richard

                          Comment

                          • Richard Bos

                            #14
                            Re: Data Files

                            bernardpace@yah oo.com (Xarky) wrote:
                            [color=blue]
                            > In my file I need to store the following (mainly for a small
                            > database):
                            > int position;
                            > char *data;
                            > int check;
                            >
                            > Also I have to add the data mentioned at EOF[/color]

                            Open the file in append mode. See the second parameter to fopen().

                            Choose whether you want:
                            - non-portable binary files (easy to read and write - just use fwrite()
                            and fread(), but be careful with that pointer - but only guaranteed to
                            be useable on the machine they were written on);
                            - portable text files (relatively easy to read and write using printf(),
                            fgets() and sscanf(), and if done right pointers are no problem, but
                            they can be relatively bulky and easy to tamper with);
                            - or whether you want to devise a portable binary format or choose a
                            portable binary format someone else invented, which can be somewhat
                            more complex to read and write (typically using functions which
                            arrange your struct members in the right byte order, and then call
                            fwrite(), and v.v. as well, of course), but can also be both portable
                            and compact.
                            Which of these options is right for you depends entirely on your
                            situation, and what the program is supposed to do. However, you might
                            get some inspiration at <http://www.wotsit.org/>.
                            [color=blue]
                            > or sometimes randomly at any position in the file, or delete at
                            > any position. Can this be done.[/color]

                            Under most popular OSes, this cannot be done in any language. It is not
                            a problem of C itself. Inserting or removing bytes in the middle of a
                            file typically involves copying it. Most databases don't actually delete
                            records; they mark them with a flag saying "this record has been
                            deleted", and either re-use them or remove them all in one go when you
                            re-index the database.
                            If you'd been a good Usenetter and read the FAQ, you'd have known this,
                            btw: <http://www.eskimo.com/~scs/C-faq/q19.14.html>.

                            Richard

                            Comment

                            • Keith Thompson

                              #15
                              Re: Data Files

                              bernardpace@yah oo.com (Xarky) writes:
                              [...][color=blue]
                              > In my file I need to store the following (mainly for a small
                              > database):
                              > int position;
                              > char *data;
                              > int check;
                              >
                              > Also I have to add the data mentioned at EOF or sometimes randomly
                              > at any position in the file, or delete at any position. Can this be
                              > done.[/color]

                              Dealing with the "char *data" could be complicated. Does "data" point
                              to a nul-terminated string, to a single character, to a (non-string)
                              character array of known size, or to something else? It almost
                              certainly doesn't make sense to write the pointer itself to a file.
                              If you want to write the stuff that it points to, you may have to have
                              variable-sized records, which means you'll have to have some way of
                              figuring out where each record starts and how big it is.

                              Inserting or deleting a record in the middle of the file is going to
                              be difficult. You would probably need to re-write everything after
                              the insertion or deletion point, or possibly the entire file. There
                              are data structures that let you impose a higher-level structure on a
                              file (so that the logical order of the records in the file doesn't
                              necessarily match the physical order), but that's probably a topic for
                              comp.programmin g rather than comp.lang.c.

                              --
                              Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                              San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                              Schroedinger does Shakespeare: "To be *and* not to be"

                              Comment

                              Working...