Thread: General Programming Question!!

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    225

    General Programming Question!!

    Hello,

    This is a general programming question but since i am making one application in C# i posted it in this section. Just wanted to know where do i store data?(application specific). I mean this is not database driven application so definitely not in database. Another choice is flat file. But that requires parsing and other complex and unmaintainable code. Yet another choice is registry. But i want to store information in bulk say few 100 of lines at a time and registry is not meant for that(i suppose). Another is .xml file, that suits my requirement. My only doubt is do professional programmers also store data like this only? in some .xml or flat files? or do they store it somewhere else?

    Thanks in advance

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Xml is an excellent format for data and settings.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by chottachatri View Post
    Another choice is flat file. But that requires parsing and other complex and unmaintainable code. [...] My only doubt is do professional programmers also store data like this only? in some .xml or flat files? or do they store it somewhere else?
    It's certainly not unusual for software to use flat files to store data; the only real difference between an .xml file and some other kind of "flat file" of text is that XML would seem slightly more maintainable if other people are involved. But lots of things like configuration files, "address books", browser data, etc are kept in text files that have their own unique format. It seems unlikely such data could be so complex that your method of storing it will end up perplexing someone else later IMO; most likely it will just be the product of one simple function, right? Your compiler certainly does some parsing of varied text files (source code) -- does the compiler's own source count as "complex and unmaintainable"?

    Depending on the nature of the data, you could serialize it; this is especially useful if it is already being used by the program as a bunch of objects or in some datatype array. For example (I don't know C#, so I don't know what the equivalent would be), if you have an array of structs like this:
    Code:
    struct {
        char name[64];
        char data[256];
        int num1;
        int num2;
    }
    You can write this directly, byte for byte, to a file (as "binary" data, since it will have zero bytes in it and the file need not be readable as text). To load the data, you read it byte for byte back using a function that will put it into structs properly -- eg, up to 64 bytes ending with '\0' into "name", then upto 256 null terminated bytes into "data", then exactly (sizeof(int)) bytes, with no null teminator, into an int. Etc. Do this in a loop and you have a whole array.

    That works fine and is pretty straightforward if, like I said, the data is being used someway like that anyhow. Obviously, using pointers in the struct (or object) will complicate that, because there is no point in writing a memory location instead of the data at that memory location!
    Last edited by MK27; 07-12-2009 at 09:21 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    Thanks Magos & MK. I really appreciate your ideas. Writing data in .xml and in plain text files in binary format are both great idea. By Writing in binary format, i can hide the contents and make it unreadable. That does my job!

    Thanks to both of you again!

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    Code:
    WeatherStation station, DateTime predictionDate
    can we define the variables in c sharp like this?i am looking through some codes here and while compiling got the error saying"are you missing a using directive or an assembly reference cs0246"
    and it is showing error for this variables. I tried to remove it but the program have used the variable name station and predictionDate in the program. So can you help me out?

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Quote Originally Posted by pokhara View Post
    Code:
    WeatherStation station, DateTime predictionDate
    can we define the variables in c sharp like this?i am looking through some codes here and while compiling got the error saying"are you missing a using directive or an assembly reference cs0246"
    and it is showing error for this variables. I tried to remove it but the program have used the variable name station and predictionDate in the program. So can you help me out?
    omg, stop spamming this question in multiple threads.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Registered User
    Join Date
    Jul 2009
    Posts
    53
    no one is replying in my thread so i posted on yours.sorry for that.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If no one is answering, it simply means no one knows or no one who has the knowledge is online at the moment!
    Posting in several threads is NOT going to help.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. General question why must of the servers written in c and not c++ ?
    By umen242 in forum Networking/Device Communication
    Replies: 3
    Last Post: 06-26-2008, 04:17 AM
  2. A general question aout programming?
    By bradt93 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-26-2008, 11:00 AM
  3. winsock - general question
    By keira in forum Windows Programming
    Replies: 1
    Last Post: 09-28-2007, 01:56 PM
  4. general programming compatability question
    By Metarectilinear in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-25-2002, 11:51 PM
  5. general question regarding a function parameter
    By mlupo in forum C Programming
    Replies: 7
    Last Post: 10-13-2002, 07:32 PM