Whats the correct way to define a random access file? Does the programmer have to create a separarte c program to accomplish this task?
Whats the correct way to define a random access file? Does the programmer have to create a separarte c program to accomplish this task?
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.
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.