【文章內(nèi)容簡介】
l data of the same type (ints, for example) use the same memory168。 All records of the same type have a fixed length168。 Data not human readable48Random Accessn Access individual records without searching through other recordsn Instant access to records in a filen Data can be inserted without destroying other datan Data previously stored can be updated or deleted without overwriting.n Implemented using fixed length records168。 Sequential files do not have fixed length records49Random Access a File fread ()n fread Transfer bytes from a file to a location in memoryn Function fread requires four arguments168。 ret = fread(buffer, size, num, myptr)。168。 the number of objects read168。 buffer: Address of first memory cell to fill168。 size: Size of one value168。 num: Maximum number of elements to copy from the file into memory168。 myptr: File pointer to a binary file opened in mode “rb” using function fopen50Random Access a File — fwrite()n fwrite Transfer bytes from a location in memory to a filen fwrite( amp。number, sizeof( int ), 1, myPtr )。 168。 amp。number Location to transfer bytes from168。 sizeof( int ) Number of bytes to transfer168。 1 For arrays, number of elements to transfer168。 In this case, one element of an array is being transferred168。 myPtr – file pointer51Random Access a File — fwrite() (cont.)n Writing structsfwrite( amp。myObject, sizeof (struct myStruct), 1, myPtr )。168。 sizeof Returns size in bytes of object in parenthesesn To write several array elements168。 Pointer to array as first argument168。 Number of elements to write as third argument52Creating a Binary File of Integers53Access Data in a Random Access Filen fseek168。 Sets file position pointer to a specific position168。 fseek( myPtr, offset, symbolic_constant)。168。 myPtr pointer to file168。 offset file position pointer (0 is first location)168。 symbolic_constant specifies where in file we are reading from168。 SEEK_SET seek starts at beginning of file168。 SEEK_CUR seek starts at current location in file168。 SEEK_END seek starts at end of filen ftell168。 Return the current position in a stream168。 ftell( myptr)168。 myPtr pointer to file54SEEK_SET SEEK_CUR SEEK_ENDorigin:當(dāng) 前存取位置 移動(dòng)后offsetfile55Read file5657Homeworkn1 hr contestn20pm – 21pm today?nftp: /第 14次作業(yè) 1215/58iH(lK+nM1qP4tS7vU9yXcBfE$hG*kJnM1pO3sR6vU9yWbAZeD$hG*jI)mL0pO3sQ5uT8xWbAZdC!gFamp。jI)mK+oN2rQ5uT7wVazYdC!gE%iH(lK+oN1qP4tS7wVayXcBfE%iH*kJnM1q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