Thread: Random Access Text file

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    1

    Random Access Text file

    Whats the correct way to define a random access file? Does the programmer have to create a separarte c program to accomplish this task?

  2. #2
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    There's not much choice. You use fcreate() or create()... They both create a random access file. There is no other file type in plain C. Any additional smarts - record access, relational, etc. are provided by code someplace.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Dkamaque View Post
    Whats the correct way to define a random access file? Does the programmer have to create a separarte c program to accomplish this task?
    Random access files are based upon records (usually in structs). Every element in the file is the same size so you can mathematically determine where each one starts... This lets you read in only the single record you want to work on.

    You would use fopen(), fread(), fwrite() and fclose() in the normal manner. But to get to each record you would have to fseek() to the correct location in the file before reading it into memory.

    Text files are bad candidates for random access because the lines are different lengths and there is no standardization of content. It can be done using a separate index file but in general test files are best read sequentially.

    All of this, as already pointed out, is your job to program.
    Last edited by CommonTater; 03-11-2011 at 09:31 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-18-2009, 01:17 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM