Loading…
Loading…
Topic
Articles and problems tagged File I/O.
Over time a disk collects files with the same name in different folders. Walk every directory, insert each file name into a binary search tree, and report a duplicate the moment a name is found already in the tree. Includes a runnable version and a real directory walk with nftw().
Build a small generic database: a file that describes its own fields, fixed-size records you can jump to with fseek, and an index file that lists records in sorted order without moving them. Uses a linked list of tagged unions to sort values of any field type.
See how the FAT file system, still used on USB sticks and memory cards, records where every file is stored: boot sector, FAT, directory and data area, clusters, and FAT chains that work like linked lists. Then decode 12-bit and 16-bit FAT entries correctly with pointers and bitwise operators.
Every file a C program opens is reached through a FILE *. Learn what that pointer points to (a structure holding a buffer and a position), how fopen, fgetc and fclose use it, and why the character read from a file must be stored in an int, never a char.