Thread: sequential vs random

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    11

    sequential vs random

    What is the difference between sequential access file and random access file

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Are these a bunch of homework questions? STFW.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    11
    No I am trying to understand the difference between access a file sequentially and randomly. How is it done in C? For example if I have 1000 files numbered 1 to 1000 and I want to access file number 57. If I do it sequentially I have to access the first 56. But I want to directly go to file number 57. How can it be done in C.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by rajabadsha
    No I am trying to understand the difference between access a file sequentially and randomly. How is it done in C? For example if I have 1000 files numbered 1 to 1000 and I want to access file number 57. If I do it sequentially I have to access the first 56. But I want to directly go to file number 57. How can it be done in C.
    Assuming the record size is fixed, you'd use some simple mathematics and a call to fseek to jump forward/backwards a certain number of bytes from the beginning/end of the file. For example, assuming 100 byte records, if you wanted to access the 57th record, you'd do an fseek to the 5600 ((57-1) *100) byte and start reading from that point.
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 09-30-2008, 12:10 AM
  2. Lesson #3 - Math
    By oval in forum C# Programming
    Replies: 2
    Last Post: 04-27-2006, 08:16 AM
  3. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 05:51 PM
  4. Replies: 1
    Last Post: 02-11-2002, 12:00 PM
  5. Best way to generate a random double?
    By The V. in forum C Programming
    Replies: 3
    Last Post: 10-16-2001, 04:11 PM