Random Access Text file

This is a discussion on Random Access Text file within the C Programming forums, part of the General Programming Boards category; Whats the correct way to define a random access file? Does the programmer have to create a separarte c program ...

  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,831
    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 08: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, 01:46 PM
  5. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 03:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21