Thread: Creating a Flast File with c

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    3

    Creating a Flast File with c

    Right now I am trying to create a Flat File using the C language and so far I'm not doing so good. I don't have any code at all but the main problem is how do I even create one of my own? I have seen many tutorials and tried working with them but sadly they will not work for me. Can someone please be of help to me?

    Thank You,

    Silver

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    What type of data are you planning to write? What information does the file need to record?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    3
    It's something for my father. He has tons of comic books and asked me to write him a program using Flat Files.

  4. #4
    Registered User
    Join Date
    Sep 2012
    Posts
    357
    Please consider using SQLite as a replacement for flat files -- according to their own documentation SQLite was designed to replace fopen(), fread(), fwrite(), fclose(); not to replace Oracle.

    If you want to stick with fopen() et al. try to start with text files. Text files are perfectly reasonable formats for a comic book flat-file database.

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    So you want to write a program which helps your father to manage his comic books collection, right?

    A flat file, as I understand it, is just a text file where each line describes a single record of your database. So it is completely up to you to decide which fields are necessary for your records and how you delimit them.

    For working with a text file you just need basic file I/O functions like fopen(), fprintf(),...
    For creating a text file you simply call fopen():
    Code:
    fp = fopen("comic_books.db", "w");
    Bye, Andreas

  6. #6
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Use structs in your program to hold the various text fields and numeric fields. In your file you'd read/write the fields variable length, delimited by TAB or comma (those are the usual conventions). That way you can easily read and edit the data file using NOTEPAD or any editor easily if you need to, or for debugging the program as it matures. Think about writing out text fields enclosed in quotes so that things like ACCESS or EXCEL can import it easily as well. Add field (column) headings as the first line to aid those utilities even more - and any other person who may just want to browse the data.

    If you need to index, sort, etc., just do so on the structs or pointers, then re-write the entire file out replacing the old one. Maintain one backup file for safety in case the program goes nutsoid. Also make a backup copy of the data file manually and store it away safely every time the data is somewhat stable.
    Last edited by nonoob; 12-12-2012 at 04:06 PM.

  7. #7
    Registered User
    Join Date
    Dec 2012
    Posts
    3
    The thing is my programming skills are not exactly all that great. I was really hoping someone could walk though this with me step by step. It'd be very nice

  8. #8
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Yes, that would be awfully nice of someone. However, no one here (that I'm aware of) will write a complete program for you. So please, help us help you.

    For starters, what kind of programs can you write? Let's find your level of expertise, and we'll go from there.

    Some might think that this is a thinly veiled attempt to get someone to do homework for you - it's up to you to prove them wrong!

  9. #9
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by Silver2100 View Post
    The thing is my programming skills are not exactly all that great. I was really hoping someone could walk though this with me step by step. It'd be very nice
    Do you even need to write a program for this or is there something wrong with Access/Open Office Base/etc that I am not aware of? You said it was for your dad.

    Just make a form for input purposes, if data entry is the reason you are using flat files.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'm going out on a limb and saying "code it", and we'll help. Your Dad will glow to have a flat file manager written by his son, and it will serve as an interesting program for you to learn on, as well. Give yourself plenty of time - that will convince everyone that it's not a homework assignment - and give you plenty of time to grow some C muscles, as well.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Edit the file using c++ without creating new file
    By pankaj454k in forum C++ Programming
    Replies: 18
    Last Post: 06-29-2010, 05:07 AM
  2. Help in creating a file in C
    By namasteall2000 in forum C Programming
    Replies: 3
    Last Post: 10-15-2009, 12:07 PM
  3. Problem with Creating File for File Processing
    By Dampecram in forum C Programming
    Replies: 2
    Last Post: 12-07-2008, 01:26 AM
  4. Creating Log File
    By smarta_982002 in forum C Programming
    Replies: 13
    Last Post: 01-31-2008, 11:04 AM
  5. Creating a New File
    By BigSter in forum C++ Programming
    Replies: 4
    Last Post: 02-11-2002, 12:54 AM