Thread: creating a small database need some hints

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    8

    creating a small database need some hints

    ok i want to create a database that wil store everythin in a text file and at the moment im in the stage that im thinging of the algorithm

    everything will be stored in a text file but im thinging of storing all the elements of the text in a class
    i used this algorithm in a previous program of mine and it works
    i mean it recognizes space and the enter i used there ascii values for it
    // Open and reads file into array
    FILE *afile;
    FILE *bfile;
    afile=fopen("sample.txt","r");
    //opens the sapmle program and stores it into an array
    for(count=0;count<340;count++)
    {
    temparray[count]=(char)fgetc(afile);
    }

    fclose(afile);
    count=0;

    for(i=0;i<340;i++)
    {
    if((temparray[i]==32) ||( temparray[i]==10))
    {
    count++;
    j=0;
    }
    else
    {
    temp2[count].name[j]=temparray[i];
    j++;
    }
    }

    my question is would this be easy for me to implement i mean lets say the search function or would it be easy to store them back to text file without everything beign deleted i mean my previous entries???
    Last edited by asim0s; 02-28-2002 at 03:49 AM.

  2. #2
    Unregistered
    Guest
    If I understand your question correctly, it is possible to change data in a file without writing all data to program, changing data within file, and then rewriting data back to file. However to do that you need to have a very structured file storage format. For example if you had a file of structs and every data member of each struct had the same size as the same data in every other struct, then you can "randomly" access the file by repositioning the file pointer with fseek() and related functions, read in just the data you want to manipulate, and the writing back just the data for that given struct (or struct member). If however, your struct has a variably sized data member, say a list, or a string, or some data member whose size is declared on the fly using dynamic memory; then this won't work. If data stored in the file is not of a standard size, then the system won't work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Creating File for File Processing
    By Dampecram in forum C Programming
    Replies: 2
    Last Post: 12-07-2008, 01:26 AM
  2. Replies: 6
    Last Post: 07-07-2008, 07:48 AM
  3. Database assignment is Killing me!
    By Boltrig in forum C Programming
    Replies: 2
    Last Post: 11-29-2007, 03:56 AM
  4. Programmers Database
    By sean345 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 09-03-2002, 01:16 AM
  5. File Database & Data Structure :: C++
    By kuphryn in forum C++ Programming
    Replies: 0
    Last Post: 02-24-2002, 11:47 AM