🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

file CS 36 – Test 3 Study Guide (not all inclusive) processing Reusability portability is used to...

file CS 36 – Test 3 Study Guide (not all inclusive) processing Reusability portability is used to efficient , storage store info , capacity. , File Processing File processing functions: o fopen() o fprintf() o fseek() o fscanf() o fwrite() o fclose() o feof() o rewind() File access modes - Know that random-access/binary mode has a b, for example "wb+" Differences between sequential and random-access Data Structures Linked lists o Inserting elements o Deleting elements Stack o push() – insert element at the start/head o pop() – remove element at the start/head Queue o enqueue() – insert element at the end/tail (maintain a pointer to the tail) o dequeue() – remove element at the start/head Start Pointers o Useful to use a struct to hold the start pointer o Can contain a counter for number of elements and tail pointer for queues Types of Linked Lists Linked List vs Arrays Header Files Why use interface and implementation files (3 primary reasons) Include Guard Interface file o How to use the header o Contains function prototypes Implementation file o How the code works o Definitions – functions and user data types code example & writing a & Function ↑ insert previous coding projects * correct "this" code File functions processing fopen() Tex t files purpose : to open a file. - used to s t o re s t re a m of c h a r a c te rs. ↳ FILE * fopen (const Char filename , Const char mode) ; - stored with Ext file extension modes - used to s t o re the source code ↳ "r"open for reading (file m u st exist) binary files ↳ "W" open for writing data in binary fo r m - Isequence of bytes ↳ "a "Open for - not easily readable appending - stored with bin file 1) ↳ "rb" "Wh" "ab mode binary in extension fseek)) ↳ moves within file file pointer to a specific location a ↳ in ++ seek (FILEastream , long int offset, in t whence ; whence options ↑ SEEK SET of the file beginning - : 4) SEEK CUR current of the file position pointer : - ↳ SEEK - END : end of the file furi tel ( ↳ write data to a file · ize- + frie(const void Aptr , size_t size , size-t count, FILE * stream) feof () ↳ check If end of file was reached nonzero If end of file reached) Int feot (FILt * Stream) ; f printf(( ↳ write formatted data to a file int fprintf(FILE stream, const char format.... ) ; + scant() ↳) to read formatted data from a file int fscant (FILE * stream , const Char format.... ); opening modes cont f close(). ~+: S e a rc h e s file. If opened ) to ↳ close an opened file fopen() loads it in memory + sets up pointer pointing to 1st Int felose (FILE * Stream) ; charac ter I t. in If unable to open , re t u r n s N U L L W +: searches file rewind). If file ex i s t, contents a re ove r w r i t t e n. If doesn't exist new file created ↳ more the file pointer to beginning of the new file Retur ns If NULL : u n ab le to open S at : searches file. If opened topen() void rewind (FILE # stream) ; loads i n to memory and s e ts up ↑ o i n te r pointing to last c h a r a c te r. opens file in reading and append mode Sequential NULL If unable to. Re t u r n s. open If file doesn't ex i st It is created Reads or end of file writes f ro m beginning to - simple data processing - ex : reading a text file line by line Random - allows file politer to more to any part of file non e near data access - , example various file needed : database system where quick access to parts of is - Da + a st ru c t u re s ↓ Inked list : data s t r u c t u re where each (node) contains a value and a reference (or link) to next mode In sequence ↳ inserting elements : adding a new node ↳ deleting elements : removing nodes. References h ave to be updated so the list still re m a i n s connected added) cremoved) Stack : follows Last In , First Out principle. Elements a re S used and popped from top of stack. 4) push :I n s e r t element at top of stack stack & dr ray ; linked list · , push(s) ; adds element 5 to top of stack ↳ popl) : removes an element from top of stack · and stack , pop)) ; re m ove s returns the top element of the st a c k (added) cremoved) First In , First out Quene : follows principle. Elements a re enquered at end , and dequered from st a r t ↳ enquenel) : insert element at end of quent linked quene enqueuels) ; array's adds 5 list · the element to end of quene * ↳ deqene)) : remove element from start of queue · queue. deene) ; and re t u r n s front element of queue removes Star t pointers : Useful in various data st r u c t u re s to keep track of starting point or head of s t r u c t u re Struc ts · for start pointers : Using a st r u c t manages start pointer along with additional Information l i ke a counter fo r the number of elements or a tail In a queue pointer Types of linked lists ↳ ) singly linked list : each node con t ai n s a va l u e and a reference to next node ↳ doubly linked list : each node contains a va l u e, a reference to n ex t mode AND previous node ↳ circular linkedList : last node re fe re n c e s first node which forms & circle Linked list us array Linked list · dynamic s i ze ~ easy to inser t and delete elements without shifting other elements · m o re memory due to storage of references usage Arrays · fixed S i ze faster access elements to indexing · rid and be of elements Inserting elements shifting · be deleting can expensive of -

Use Quizgecko on...
Browser
Browser