{"id":24484032,"url":"https://github.com/sebastian-nunez/systems-programming","last_synced_at":"2026-05-22T07:01:57.947Z","repository":{"id":61598619,"uuid":"527579328","full_name":"sebastian-nunez/systems-programming","owner":"sebastian-nunez","description":null,"archived":false,"fork":false,"pushed_at":"2022-11-28T15:20:06.000Z","size":31924,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T20:36:29.064Z","etag":null,"topics":["bash","c","operating-system","system-programming","unix"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sebastian-nunez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-22T13:33:59.000Z","updated_at":"2023-10-17T04:43:08.000Z","dependencies_parsed_at":"2023-01-22T14:45:15.958Z","dependency_job_id":null,"html_url":"https://github.com/sebastian-nunez/systems-programming","commit_stats":null,"previous_names":["sebastian-nunez/systems-programming"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sebastian-nunez/systems-programming","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastian-nunez%2Fsystems-programming","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastian-nunez%2Fsystems-programming/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastian-nunez%2Fsystems-programming/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastian-nunez%2Fsystems-programming/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sebastian-nunez","download_url":"https://codeload.github.com/sebastian-nunez/systems-programming/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastian-nunez%2Fsystems-programming/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33333299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-21T12:23:38.849Z","status":"online","status_checked_at":"2026-05-22T02:00:06.671Z","response_time":265,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","c","operating-system","system-programming","unix"],"created_at":"2025-01-21T13:13:28.201Z","updated_at":"2026-05-22T07:01:57.878Z","avatar_url":"https://github.com/sebastian-nunez.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# COP4338 - Systems Programming\n\n## Table of Contents\n\n- [**Chapter 0: UNIX Basics**](#chapter-0-unix-basics)\n\n  - [UNIX Cheat Sheet](#unix-cheat-sheet)\n  - [.vimrc](#vimrc)\n  - [.nanorc](#nanorc)\n\n- [**Chapter 1: Basics, Command Line Arguments, and Makefile**](#chapter-1-basics-command-line-arguments-and-makefile)\n\n  - [Command Line Arguments (argc, argv)](#command-line-arguments-argc-argv)\n  - [Command Line Arguments (Validation)](#command-line-arguments-validation)\n  - [Command Line Arguments and Files](#command-line-arguments-and-files)\n  - [Macros (#define directive)](#macros-define-directive)\n  - [Single Step Compilation](#single-step-compilation)\n  - [Modular Compilation](#modular-compilation)\n  - [Makefiles](#makefiles)\n  - [Makefile (Sample)](#makefile-sample)\n\n- [**Chapter 2: Variables, Data Types, and Random Numbers**](#chapter-2-variables-data-types-and-random-numbers)\n\n  - [Variables](#variables)\n  - [Variable Declaration (Integers)](#variable-declaration-integers)\n  - [Identifiers](#identifiers)\n  - [Keywords Table](#keywords-table)\n  - [Arithmetic Expressions](#arithmetic-expressions)\n  - [Precendence](#precendence)\n  - [Double vs Int](#double-vs-int)\n  - [Floating Point Numbers](#floating-point-numbers)\n  - [Printing Floating Point Numbers](#printing-floating-point-numbers)\n  - [Floating Point Division by Zero (-inf, +inf)](#floating-point-division-by-zero--inf-inf)\n  - [Scientific Notation](#scientific-notation)\n  - [Constants](#constants)\n  - [Math Library \\\u003cmath.h\\\u003e](#math-library-mathh)\n  - [Integer Division (floor division)](#integer-division-floor-division)\n  - [Integer Division by Zero (NaN, Undefined)](#integer-division-by-zero-nan-undefined)\n  - [Modulo (%)](#modulo-)\n  - [Extracting Digits (%, /)](#extracting-digits--)\n  - [Random Numbers in Range (%)](#random-numbers-in-range-)\n  - [Type Conversions](#type-conversions)\n  - [Type Casting](#type-casting)\n  - [Binary](#binary)\n  - [ASCII Table](#ascii-table)\n  - [Character Data Type](#character-data-type)\n  - [Strings](#strings)\n  - [Strings as Character Arrays - char\\[\\]](#strings-as-character-arrays---char)\n  - [Scanf and Whitespace](#scanf-and-whitespace)\n  - [Integer Overflow](#integer-overflow)\n  - [Numeric Data Types](#numeric-data-types)\n  - [Floating Point Data Types](#floating-point-data-types)\n  - [Unsigned Data Types](#unsigned-data-types)\n  - [Random Numbers \\\u003cstdlib.h\\\u003e and \\\u003ctime.h\\\u003e](#random-numbers-stdlibh-and-timeh)\n  - [Format Specifier Table \\\u003cstdio.h\\\u003e](#format-specifier-table-stdioh)\n  - [Input using Scanf (I/O)](#input-using-scanf-io)\n\n- [**Chapter 3: Control Flow and String Manipulation**](#chapter-3-control-flow-and-string-manipulation)\n\n  - [Control Statements (if, else, else if)](#control-statements-if-else-else-if)\n  - [Equality Operator (==)](#equality-operator-)\n  - [Integer, Character and Floating Point Equality](#integer-character-and-floating-point-equality)\n  - [Relational Operators (\\\u003c, \\\u003e, \\\u003c=,\\\u003e=)](#relational-operators---)\n  - [Logical Operators (\\\u0026\\\u0026, ||, !)](#logical-operators---)\n  - [Bitwise Operators (\\\u0026, |, \\\u003c\\\u003c, \\\u003e\\\u003e)](#bitwise-operators----)\n  - [Order of Evaluation](#order-of-evaluation)\n  - [Switch Case Statement](#switch-case-statement)\n  - [Boolean Data Type \\\u003cstdbool.h\\\u003e](#boolean-data-type-stdboolh)\n  - [String Comparison (strcmp)](#string-comparison-strcmp)\n  - [String Indexing](#string-indexing)\n  - [String Methods \\\u003cstring.h\\\u003e](#string-methods-stringh)\n  - [Character Operations \\\u003cctype.h\\\u003e](#character-operations-ctypeh)\n  - [Ternary Operator (?)](#ternary-operator-)\n  - [Floating Point Comparison (delta)](#floating-point-comparison-delta)\n  - [Short Circuit Evaluation](#short-circuit-evaluation)\n\n- [**Chapter 4: Loops, Scope and Enums**](#chapter-4-loops-scope-and-enums)\n\n  - [While Loops](#while-loops)\n  - [For Loops](#for-loops)\n  - [Pre vs Post Operators](#pre-vs-post-operators)\n  - [Do-While Loops](#do-while-loops)\n  - [Loops and Strings](#loops-and-strings)\n  - [Nested Loops](#nested-loops)\n  - [Break Statement](#break-statement)\n  - [Continue Statement](#continue-statement)\n  - [Loop Indexing](#loop-indexing)\n  - [Variable Scope](#variable-scope)\n  - [Enums](#enums)\n  - [Enums Example](#enums-example)\n\n- [**Chapter 5: Arrays and Strings**](#chapter-5-arrays-and-strings)\n\n  - [General Concept](#general-concept)\n  - [Array Declaration](#array-declaration)\n  - [Array Initialization](#array-initialization)\n  - [Array Iteration (+ Out of Bounds)](#array-iteration--out-of-bounds)\n  - [Multiple Arrays](#multiple-arrays)\n  - [Swapping Values](#swapping-values)\n  - [2D Arrays](#2d-arrays)\n  - [Character Arrays](#character-arrays)\n  - [String Library \\\u003cstring.h\\\u003e](#string-library-stringh)\n  - [I/O: scanf vs fgets \\\u003cstdio.h\\\u003e](#io-scanf-vs-fgets-stdioh)\n  - [Type Checking and Conversion \\\u003cctype.h\\\u003e](#type-checking-and-conversion-ctypeh)\n  - [Arrays and Strings (Example)](#arrays-and-strings-example)\n  - [Annual Salary (Example)](#annual-salary-example)\n\n- [**Chapter 6: Functions**](#chapter-6-functions)\n\n  - [Basics](#basics)\n  - [Parameters](#parameters)\n  - [Void Functions](#void-functions)\n  - [Modular Development](#modular-development)\n  - [Modular Math Expressions](#modular-math-expressions)\n  - [Unit Testing](#unit-testing)\n  - [Assertions (Unit Testing) \u003cassert.h\u003e](#assertions-unit-testing-asserth)\n  - [How Functions Work](#how-functions-work)\n  - [Pass by Value](#pass-by-value)\n  - [Pass by Pointer/Reference](#pass-by-pointerreference)\n  - [Functions with Array Parameters](#functions-with-array-parameters)\n  - [Const and Array Parameters](#const-and-array-parameters)\n  - [Strings as Parameters](#strings-as-parameters)\n  - [Function Protope/Declaration](#function-protopedeclaration)\n  - [Variable Scope (Functions)](#variable-scope-functions)\n  - [Preprocessor and Include](#preprocessor-and-include)\n  - [Header Guards](#header-guards)\n  - [Separate Files](#separate-files)\n\n- [**Chapter 7: Structs**](#chapter-7-structs)\n\n  - [Defining Structs and Typedef](#defining-structs-and-typedef)\n  - [Returning Structs from Functions](#returning-structs-from-functions)\n  - [Structs and Arrays](#structs-and-arrays)\n  - [Structs, Arrays, and Functions (Example)](#structs-arrays-and-functions-example)\n  - [Derefencing a Pointer to a Struct (-\u003e)](#derefencing-a-pointer-to-a-struct--)\n  - [Seperate Files for Structs](#seperate-files-for-structs)\n\n- [**Chapter 8: Pointers**](#chapter-8-pointers)\n\n  - [Why Pointers](#why-pointers)\n  - [Pointer Basics](#pointer-basics)\n  - [Dereferencing a Pointer](#dereferencing-a-pointer)\n  - [Null Pointer](#null-pointer)\n  - [Common Pointer Mistakes](#common-pointer-mistakes)\n  - [**Malloc Function**](#malloc-function)\n  - [**Free Function**](#free-function)\n  - [Pointers with Structs](#pointers-with-structs)\n  - [String Functions with Pointers](#string-functions-with-pointers)\n  - [String Searching Methods (Table)](#string-searching-methods-table)\n  - [Malloc for Arrays and Strings](#malloc-for-arrays-and-strings)\n  - [Dynamic Copy of a String](#dynamic-copy-of-a-string)\n  - [**Realloc Function**](#realloc-function)\n    - [Dynamically Reallocating Size of an Array (Code)](#dynamically-reallocating-size-of-an-array-code)\n  - [**Vector ADT**](#vector-adt)\n    - [vector.h](#vectorh)\n    - [Vector Implementation](#vector-implementation)\n    - [**Vector Functions (Table)**](#vector-functions-table)\n    - [Segmentation Fault](#segmentation-fault)\n  - [LinkedList vs. Vector](#linkedlist-vs-vector)\n    - [LinkedList (Code)](#linkedlist-code)\n  - [**Memory Regions - Heap and Stack (Table)**](#memory-regions---heap-and-stack-table)\n  - [Memory Leaks](#memory-leaks)\n\n- [**Chapter 9: Input and Output**](#chapter-9-input-and-output)\n  - [File Pointer: stdout (fprintf)](#file-pointer-stdout-fprintf)\n  - [File Pointer: stdin (fscanf)](#file-pointer-stdin-fscanf)\n  - [Formatted Output (Table)](#formatted-output-table)\n    - [Integer Formatting](#integer-formatting)\n    - [String Formatting](#string-formatting)\n  - [Flushing Output (fflush)](#flushing-output-fflush)\n  - [**Input Parsing**](#input-parsing)\n    - [Input Validation](#input-validation)\n  - [Parsing Input String (sscanf)](#parsing-input-string-sscanf)\n    - [Parsing Input (sscanf and fgets) Example](#parsing-input-sscanf-and-fgets-example)\n  - [**File Input and Output**](#file-input-and-output)\n    - [**Writting to Files (fopen)**](#writting-to-files-fopen)\n  - [**Parsing Through an Entire File (!feof)**](#parsing-through-an-entire-file-feof)\n  - [Binary Files](#binary-files)\n    - [Writting to a Binary Files](#writting-to-a-binary-files)\n    - [Reading from a Binary File](#reading-from-a-binary-file)\n\n## Chapter 0: UNIX Basics\n\n### UNIX Cheat Sheet\n\n![UNIX Cheat Sheet](./images/0.%20UNIX%20Cheat%20Sheet.png)\n\n## .vimrc\n\n```vim\n\"\"set background=dark\n\"\"set termguicolors\n\"\"colorscheme fleet2\n\nsyntax on\nset number\nset expandtab\nset tabstop=4\nset shiftwidth=4\nset ignorecase\nset smarttab\nset smartcase\n\"\"set showmatch\nset history=500\nset lbr\nset tw=500\nset ai \"Auto Indent\"\nset wrap \"Wrap Lines\"\nset hlsearch\nset lazyredraw\nset magic\nset wildmenu\n\n\" Ignore compiled files\nset wildignore=*.o,*~,*.pyc\nif has(\"win16\") || has(\"win32\")\n    set wildignore+=.git\\*,.hg\\*,.svn\\*\nelse\n    set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store\nendif\n\n\" Set to auto read when a file is changed from the outside\nset autoread\nau FocusGained,BufEnter * checktime\n\n\" Configure backspace so it acts as it should act\nset backspace=eol,start,indent\nset whichwrap+=\u003c,\u003e,h,l\n\n\" Enable filetype plugins\nfiletype on\nfiletype plugin on\nfiletype indent on\n\n\" in makefiles, don't expand tabs to spaces, since actual tab characters are\n\" needed, and have indentation at 8 chars to be sure that all indents are tabs\n\" (despite the mappings later):\nautocmd FileType make set noexpandtab shiftwidth=8 softtabstop=0\n\n\" for C-like  programming where comments have explicit end\n\" characters, if starting a new line in the middle of a comment automatically\n\" insert the comment leader characters:\nautocmd FileType c,cpp,java set formatoptions+=ro\nautocmd FileType c set omnifunc=ccomplete#Complete\n\n\" add completion for xHTML\nautocmd FileType xhtml,html set omnifunc=htmlcomplete#CompleteTags\n\n\" Return to last edit position when opening files (You want this!)\nau BufReadPost * if line(\"'\\\"\") \u003e 1 \u0026\u0026 line(\"'\\\"\") \u003c= line(\"$\") | exe \"normal! g'\\\"\" | endif\n\n\" Delete trailing white space on save, useful for some filetypes ;)\nfun! CleanExtraSpaces()\n    let save_cursor = getpos(\".\")\n    let old_query = getreg('/')\n    silent! %s/\\s\\+$//e\n    call setpos('.', save_cursor)\n    call setreg('/', old_query)\nendfun\n\ninoremap { {}\u003cEsc\u003eha\ninoremap ( ()\u003cEsc\u003eha\ninoremap [ []\u003cEsc\u003eha\ninoremap \" \"\"\u003cEsc\u003eha\ninoremap ' ''\u003cEsc\u003eha\ninoremap ` ``\u003cEsc\u003eha\n\n\" Output the current syntax group\nnnoremap \u003cf10\u003e :echo \"hi\u003c\" . synIDattr(synID(line(\".\"),col(\".\"),1),\"name\") . '\u003e trans\u003c'\n\\ . synIDattr(synID(line(\".\"),col(\".\"),0),\"name\") . \"\u003e lo\u003c\"\n\\ . synIDattr(synIDtrans(synID(line(\".\"),col(\".\"),1)),\"name\") . \"\u003e\"\u003ccr\u003e\n\n```\n\n### .nanorc\n\n```vim\nset atblanks        # wrap line at blanks.\nset softwrap        # Enable softwrap of lines.\nset tabsize 4       # Sets tab-to-spaces size to 4.\nset tabstospaces    # Converts TAB key press to spaces.\nset linenumbers     # Lines are numbered.\nset casesensitive   # Case insensitive search.\nset historylog      # Save the last 100 history searches for later use.\nset positionlog     # Saves the cursor position between editing sessions.\nset autoindent      # A new line will have the same number of leading spaces as the previous one.\nset brackets \"\"')\u003e]}\"\nset matchbrackets \"(\u003c[{)\u003e]}\"\nset smooth\n\n```\n\n[Back to top](#table-of-contents)\n\n## Chapter 1: Basics, Command Line Arguments, and Makefile\n\n### Command Line Arguments (argc, argv)\n\n![Command Line Arguments (argc, argv)](./images/1.13%20Command%20Line%20Arguments.png)\n\n### Command Line Arguments (Validation)\n\n![Command Line Arguments (Validation)](\u003c./images/1.13%20Validation%20(argc%20and%20argv).png\u003e)\n\n### Command Line Arguments and Files\n\n![Command Line Arguments and Files](./images/1.14%20Command%20Line%20Args%20and%20Files.png)\n\n### Macros (#define directive)\n\n![Macros (#define directive)](\u003c./images/1.15%20%23define%20Directive%20(macro).png\u003e)\n\n### Single Step Compilation\n\n![Single Step Compilation](./images/1.16%20Single%20Step%20Compilation.png)\n[Back to top](#table-of-contents)\n\n### Modular Compilation\n\n![Modular Compilation](./images/1.16%20Modular%20Compilation.png)\n\n### Makefiles\n\n![Makefiles](./images/1.17%20Makefiles.png)\n\n### Makefile (Sample)\n\n![Makefiles (Sample)](./images/1.17%20Sample%20Makefile.png)\n\n[Back to top](#table-of-contents)\n\n## Chapter 2: Variables, Data Types, and Random Numbers\n\n### Variables\n\n![Variables](./images/2.1%20Variables.png)\n\n### Variable Declaration (Integers)\n\n![Variable Declaration (Integers)](\u003c./images/2.2%20Variable%20Declaration%20(int).png\u003e)\n\n### Identifiers\n\n![Identifiers](./images/2.3%20Identifiers.png)\n\n### Keywords Table\n\n![Keywords Table](./images/2.3%20Keywords.png)\n[Back to top](#table-of-contents)\n\n### Arithmetic Expressions\n\n![Arithmetic Expressions](./images/2.4%20Arithmetic%20Expressions.png)\n\n### Precendence\n\n![Precendence](./images/2.4%20Precendence.png)\n\n### Double vs Int\n\n![Double vs Int](./images/2.7%20Double%20vs%20Int.png)\n\n### Floating Point Numbers\n\n![Floating Point Numbers](./images/2.7%20Floating%20Point%20Numbers.png)\n\n### Printing Floating Point Numbers\n\n![Printing Floating Point Numbers](./images/2.7%20Printing%20Floating%20Points.png)\n\n### Floating Point Division by Zero (-inf, +inf)\n\n![Floating Point Division by Zero (-inf, +inf)](./images/2.7%20Floating%20Point%20Division%20by%20Zero.png)\n[Back to top](#table-of-contents)\n\n### Scientific Notation\n\n![Scientific Notation](./images/2.8%20Scientific%20Notation.png)\n\n### Constants\n\n![Constants](./images/2.9%20Constants.png)\n\n### Math Library \u003cmath.h\u003e\n\n![Math Library \u003cmath.h\u003e](./images/2.10%20Math%20Library%20%3Cmath.h%3E.png)\n\n### Integer Division (floor division)\n\n![Integer Division](./images/2.11%20Integer%20Division.png)\n\n### Integer Division by Zero (NaN, Undefined)\n\n![Integer Division by Zero (NaN, Undefined)](./images/2.11%20Integer%20Division%20by%20Zero.png)\n\n### Modulo (%)\n\n![Modulo (%)](./images/2.11%20Modulo.png)\n\n### Extracting Digits (%, /)\n\n![Extracting Digits (%, /)](./images/2.11%20Getting%20Digits.png)\n\n### Random Numbers in Range (%)\n\n![Random Numbers](./images/2.11%20Random%20Numbers.png)\n\n### Type Conversions\n\n![Type Conversions](./images/2.12%20Type%20Conversion.png)\n\n### Type Casting\n\n[Back to top](#table-of-contents)\n\n![Type Casting](./images/2.12%20Type%20Casting.png)\n\n### Binary\n\n![Binary](./images/2.13%20Binary.png)\n\n### ASCII Table\n\n![ASCII Table](./images/2.14%20ASCII%20Table.png)\n\n### Character Data Type\n\n![Character Data Type](./images/2.14%20Characters.png)\n\n### Strings\n\n![Strings](./images/2.15%20Strings.png)\n\n### Strings as Character Arrays - char[]\n\n![Strings as Character Arrays - char[]](./images/2.15%20String%20as%20char%5B%5D.png)\n\n### Scanf and Whitespace\n\n![Scanf and Whitespace](./images/2.15%20scanf%20and%20Whitespace.png)\n\n### Integer Overflow\n\n![Integer Overflow](./images/2.16%20Integer%20Overflow.png)\n![Integer Overflow](./images/2.16%20Overflow%20Error.png)\n[Back to top](#table-of-contents)\n\n### Numeric Data Types\n\n![Numeric Data Types](./images/2.17%20Numeric%20Data%20Types.png)\n\n### Floating Point Data Types\n\n![Floating Point Data Types](./images/2.17%20Floating%20Point%20Data%20Types.png)\n\n### Unsigned Data Types\n\n![Unsigned Data Types](./images/2.17%20Unsigned%20Data%20Types.png)\n\n### Random Numbers \u003cstdlib.h\u003e and \u003ctime.h\u003e\n\n![Random Numbers \u003cstdlib.h\u003e and \u003ctime.h\u003e](./images/2.19%20Random%20Numbers%20%3Ctime.h%3E.png)\n\n### Format Specifier Table \u003cstdio.h\u003e\n\n![Format Specifier Table \u003cstdio.h\u003e](./images/2.20%20Format%20Specifier%20%3Cstdio.h%3E.png)\n\n### Input using Scanf (I/O)\n\n[Back to top](#table-of-contents)\n\n![Input using Scanf (I/O)](./images/2.20%20scanf.png)\n\n[Back to top](#table-of-contents)\n\n## Chapter 3: Control Flow and String Manipulation\n\n### Control Statements (if, else, else if)\n\n![Control Statements (if, else, else if)](./images/3.1%20If-else%20if-else.png)\n\n### Equality Operator (==)\n\n![Equality Operator (==)](./images/3.2%20Equality%20Operator.png)\n\n### Integer, Character and Floating Point Equality\n\n![Integer, Character and Floating Point Equality](\u003c./images/3.2%20ints%2C%20chars%2C%20and%20floats%20(%3D%3D).png\u003e)\n\n### Relational Operators (\u003c, \u003e, \u003c=,\u003e=)\n\n[Back to top](#table-of-contents)\n\n![Relational Operators (\u003c, \u003e, \u003c=,\u003e=)](./images/3.4%20Relational%20Operators.png)\n\n### Logical Operators (\u0026\u0026, ||, !)\n\n![Logical Operators (\u0026\u0026, ||, !)](./images/3.5%20Logical%20Operators.png)\n![Logical Operators (\u0026\u0026, ||, !) C](\u003c./images/3.5%20Logical%20Operators%20(C).png\u003e)\n\n### Bitwise Operators (\u0026, |, \u003c\u003c, \u003e\u003e)\n\n![Bitwise Operators (\u0026, |, \u003c\u003c, \u003e\u003e)](./images/3.10%20Bitwise%20Operators.png)\n\n### Order of Evaluation\n\n![Order of Evaluation](./images/3.10%20Order%20of%20Evaluation.png)\n[Back to top](#table-of-contents)\n\n### Switch Case Statement\n\n![OSwitch Case Statement](./images/3.11%20Switch%20Statement.png)\n![OSwitch Case Statement](\u003c./images/3.11%20Switch%20(No%20Break).png\u003e)\n\n### Boolean Data Type \u003cstdbool.h\u003e\n\n![Boolean Data Type \u003cstdbool.h\u003e](./images/3.12%20Boolean%20%3Cstdbool.h%3E.png)\n\n### String Comparison (strcmp)\n\n![String Comparison (strcmp)](\u003c./images/3.13%20String%20Comparison%20(strcmp).png\u003e)\n![String Comparison Common Errors](./images/3.13%20String%20Error.png)\n\n### String Indexing\n\n![String Indexing](./images/3.14%20String%20Index.png)\n\n### String Methods \u003cstring.h\u003e\n\n![String Methods \u003cstring.h\u003e](./images/3.14%20String%20Methods%20%3Cstring.h%3E.png)\n[Back to top](#table-of-contents)\n\n### Character Operations \u003cctype.h\u003e\n\n![Character Operations \u003cctype.h\u003e](./images/3.15%20Character%20Operations%20%3Cctype.h%3E.png)\n\n### Ternary Operator (?)\n\n![Ternary Operator (?)](\u003c./images/3.16%20Ternary%20Operator%20(%3F).png\u003e)\n\n## Floating Point Comparison (delta)\n\n![Floating Point Comparison (delta)](\u003c./images/3.17%20Float%20Comparison%20(delta).png\u003e)\n[Back to top](#table-of-contents)\n\n### Short Circuit Evaluation\n\n![Short Circuit Evaluation](./images/3.18%20Short%20Circuit%20Evaluation.png)\n\n[Back to top](#table-of-contents)\n\n## Chapter 4: Loops, Scope and Enums\n\n### While Loops\n\n![While Loops](./images/4.2%20While%20Loops.png)\n\n### For Loops\n\n![For Loops](./images/4.4%20For%20Loops.png)\n![For Loops](./images/4.4%20For%20Loop%20Styling.png)\n[Back to top](#table-of-contents)\n\n### Pre vs Post Operators\n\n![Pre vs Post Operators](./images/4.4%20Pre%20vs%20Post%20Increment.png)\n\n### Do-While Loops\n\n![Do-While Loops](./images/4.6%20Do-While%20Loops.png)\n\n### Loops and Strings\n\n![Loops and Strings](./images/4.7%20Loops%20and%20Strings.png)\n\n### Nested Loops\n\n![Nested Loops](./images/4.8%20Nested%20Loops.png)\n[Back to top](#table-of-contents)\n\n### Break Statement\n\n![Break Statement](./images/4.10%20Break%20Statement.png)\n\n### Continue Statement\n\n![Continue Statement](./images/4.10%20Continue%20Statement.png)\n\n### Loop Indexing\n\n![Loop Indexing](./images/4.11%20Loop%20Index.png)\n[Back to top](#table-of-contents)\n\n### Variable Scope\n\n![Variable Scope](./images/4.11%20Variable%20Scope.png)\n\n### Enums\n\n![Enums](./images/4.12%20Enums.png)\n\n### Enums Example\n\n![Enums Example](./images/4.12%20Enum%20Example.png)\n\n```c\n#include \u003cstdio.h\u003e\n\n/* Manual controller for traffic light */\nint main(void) {\n    enum LightState { LS_RED,\n                      LS_GREEN,\n                      LS_YELLOW,\n                      LS_DONE };\n    enum LightState lightVal;\n    char userCmd;\n\n    lightVal = LS_RED;\n    userCmd = '-';\n\n    printf(\"User commands: n (next), r (red), q (quit).\\n\\n\");\n\n    lightVal = LS_RED;\n    while (lightVal != LS_DONE) {\n        if (lightVal == LS_GREEN) {\n            printf(\"Green light  \");\n            scanf(\" %c\", \u0026userCmd);\n            if (userCmd == 'n') {  // Next\n                lightVal = LS_YELLOW;\n            }\n        } else if (lightVal == LS_YELLOW) {\n            printf(\"Yellow light  \");\n            scanf(\" %c\", \u0026userCmd);\n            if (userCmd == 'n') {  // Next\n                lightVal = LS_RED;\n            }\n        } else if (lightVal == LS_RED) {\n            printf(\"Red light  \");\n            scanf(\" %c\", \u0026userCmd);\n            if (userCmd == 'n') {  // Next\n                lightVal = LS_GREEN;\n            }\n        }\n\n        if (userCmd == 'r') {  // Force immediate red\n            lightVal = LS_RED;\n        } else if (userCmd == 'q') {  // Quit\n            lightVal = LS_DONE;\n        }\n    }\n\n    printf(\"Quit program.\\n\");\n\n    return 0;\n}\n\n```\n\n[Back to top](#table-of-contents)\n\n## Chapter 5: Arrays and Strings\n\n### General Concept\n\n![General](./images/5.1.%20Arrays%20General.png)\n\n### Array Declaration\n\n![Array Declaration](./images/5.2%20Array%20Declaration.png)\n\n### Array Initialization\n\n![Array Initialization](./images/5.3%20Array%20Initialization.png)\n\n### Array Iteration (+ Out of Bounds)\n\n![Array Iteration](./images/5.4%20Array%20Iteration.png)\n![Array Out of Bounds](./images/5.4%20Out%20of%20Bounds.png)\n\n### Multiple Arrays\n\n![Multiple Arrays](./images/5.5%20Multiple%20Arrays.png)\n[Back to top](#table-of-contents)\n\n### Swapping Values\n\n![Swapping Values](./images/5.6%20Swapping%20Values.png)\n\n### 2D Arrays\n\n![2D Arrays](./images/5.9%202D%20Arrays.png)\n\n### Character Arrays\n\n![Character Arrays](./images/5.10%20Character%20Arrays.png)\n![Character Arrays Common Errors](\u003c./images/5.10%20String%20Error%20(strcpy).png\u003e)\n\n### String Library \u003cstring.h\u003e\n\n![String Library 1](./images/5.11%20String%20Library%20%3Cstring.h%3E.png)\n![String Library 2](./images/5.11%20String%20Function%20%3Cstring.h%3E.png)\n\n### I/O: scanf vs fgets \u003cstdio.h\u003e\n\n![I/O: scanf vs fgets](\u003c./images/5.11%20User%20Input%20(scanf%20and%20fgets).png\u003e)\n[Back to top](#table-of-contents)\n\n### Type Checking and Conversion \u003cctype.h\u003e\n\n![Type Checking](./images/5.12%20Character%20Checking%20%3Cctype.h%3E.png)\n![Type Conversion](./images/5.12%20Character%20Conversion%20%3Cctype.h%3E.png)\n\n### Arrays and Strings (Example)\n\n![Arrays and Strings (Example)](./images/5.13%20Arrays%20and%20Strings.png)\n\n### Annual Salary (Example)\n\n![Annual Salary (Example)](./images/5.14%20Example.png)\n\n```c\n#include \u003cstdbool.h\u003e\n#include \u003cstdio.h\u003e\n\nint main(void) {\n    const int BASE_TABLE_ELEMENTS = 5;\n    const int MAX_ELEMENTS = 10;\n    int annualSalary;\n    double taxRate;\n    int taxToPay;\n    int totalSalaries;\n    int totalTaxes;\n    int numSalaries;\n    bool keepLooking;\n    int i;\n\n    int salaryBase[] = {20000, 50000, 100000, 999999999};\n    double taxBase[] = {.10, .20, .30, .40};\n    int annualSalaries[MAX_ELEMENTS];\n    int taxesToPay[MAX_ELEMENTS];\n\n    numSalaries = 0;\n\n    printf(\"\\nEnter annual salary (0 to exit): \\n\");\n    scanf(\"%d\", \u0026annualSalary);\n\n    while ((annualSalary \u003e 0) \u0026\u0026 (numSalaries \u003c MAX_ELEMENTS)) {\n        i = 0;\n        taxRate = 0;\n        keepLooking = true;\n\n        // Search for appropriate table row for given annualSalary\n        while ((i \u003c BASE_TABLE_ELEMENTS) \u0026\u0026 keepLooking) {\n            if (annualSalary \u003c= salaryBase[i]) {\n                taxRate = taxBase[i];\n                keepLooking = false;\n            } else {\n                ++i;\n            }\n        }  // End inner while loop (search for appropriate table row)\n\n        taxToPay = (int)(annualSalary * taxRate);  // Truncate tax to an integer amount\n        annualSalaries[numSalaries] = annualSalary;\n        taxesToPay[numSalaries] = taxToPay;\n\n        printf(\"Annual salary: %d\", annualSalaries[numSalaries]);\n        printf(\"\\tTax rate: %lf\", taxRate);\n        printf(\"\\tTax to pay: %d\\n\", taxesToPay[numSalaries]);\n        ++numSalaries;\n\n        // Get the next annual salary\n        printf(\"\\nEnter annual salary (0 to exit): \\n\");\n        scanf(\"%d\", \u0026annualSalary);\n    }  // End outer while loop (valid annualSalary entered)\n\n    // Sum the annual salaries and taxes to pay and print the totals\n    totalSalaries = 0;\n    totalTaxes = 0;\n\n    for (i = 0; i \u003c numSalaries; ++i) {\n        totalSalaries += annualSalaries[i];\n        totalTaxes += taxesToPay[i];\n    }\n    printf(\"\\nTotal salaries: %d\", totalSalaries);\n    printf(\"\\tTotal taxes: %d\\n\", totalTaxes);\n\n    return 0;\n}\n\n```\n\n[Back to top](#table-of-contents)\n\n## Chapter 6: Functions\n\n### Basics\n\n![Basics](./images/6.1%20Basic%20Functions.png)\n\n### Parameters\n\n![Parameters](./images/6.1%20Parameters.png)\n![Parameters](./images/6.1%20Void%20Parameter.png)\n\n### Void Functions\n\n![Void Functions](./images/6.2%20Void%20Functions.png)\n\n### Modular Development\n\n![Modular Development](./images/6.3%20Modular%20Development.png)\n\n### Modular Math Expressions\n\n![Modular Math Expressions](./images/6.4%20Modular%20Math%20Expressions.png)\n[Back to top](#table-of-contents)\n\n### Unit Testing\n\n![Unit Testing](./images/6.7%20Unit%20Testing.png)\n\n### Assertions (Unit Testing) \u003cassert.h\u003e\n\n![Assertions (Unit Testing) \u003cassert.h\u003e](./images/6.7%20Assert%20%3Cassert.h%3E.png)\n\n### How Functions Work\n\n![How Functions Work](./images/6.8%20How%20Functions%20Work.png)\n\n### Pass by Value\n\n![Pass by Value](./images/6.10%20Pass%20by%20Value.png)\n\n### Pass by Pointer/Reference\n\n![Pass by Pointer/Reference](./images/6.10%20Pass%20by%20pointer.png)\n[Back to top](#table-of-contents)\n\n### Functions with Array Parameters\n\n![Functions with Array Parameters](./images/6.11%20Functions%20With%20Arrays%20Params.png)\n\n### Const and Array Parameters\n\n![Const and Array Parameters](./images/6.11%20Const%20and%20Array%20Parameters.png)\n\n### Strings as Parameters\n\n![Strings as Parameters](./images/6.12%20Strings%20as%20Parameters.png)\n\n### Function Protope/Declaration\n\n[Back to top](#table-of-contents)\n\n![Function Prototype/Declaration](./images/6.14%20Variable%20Scope.png)\n\n### Variable Scope (Functions)\n\n![Variable Scope (Functions)](./images/6.14%20Variable%20Scope.png)\n\n### Preprocessor and Include\n\n![Header Guards](./images/6.16%20Preprocessor%20and%20Include.png)\n\n### Header Guards\n\n![Header Guards](./images/6.17%20Header%20Guards.png)\n\n### Separate Files\n\n![Separate Files](./images/6.17%20Separate%20Files.png)\n\n[Back to top](#table-of-contents)\n\n## **Chapter 7: Structs**\n\n- [**Chapter 7: Structs**](#chapter-7-structs)\n  - [Defining Structs and Typedef](#defining-structs-and-typedef)\n  - [Returning Structs from Functions](#returning-structs-from-functions)\n  - [Structs and Arrays](#structs-and-arrays)\n  - [Structs, Arrays, and Functions (Example)](#structs-arrays-and-functions-example)\n  - [Seperate Files for Structs](#seperate-files-for-structs)\n\n### Defining Structs and Typedef\n\n![Defining Structs and Typedef](./images//7.1%20Defining%20Structs%20and%20Typedef.png)\n\n### Returning Structs from Functions\n\n![Returning Structs from Functions](./images/7.2%20Returning%20Structs%20from%20Functions.png)\n\n### Structs and Arrays\n\n![Structs and Arrays](./images/7.3%20Structs%20and%20Arrays.png)\n\n### Structs, Arrays, and Functions (Example)\n\nA programmer commonly uses structs, arrays, and functions together. Consider a program that allows a reservations agent to reserve seats for people, useful for a theater, an airplane, etc. The below program defines a Seat struct whose data members are a person's first name, last name, and the amount paid for the seat. The program declares an array of 5 seats to represent the theater, airplane, etc., initializes all seats to being empty (indicated by a first name of \"empty\"), and then allows a user to enter commands to print all seats, reserve a seat, or quit.\n\n```c\n#include \u003cstdbool.h\u003e\n#include \u003cstdio.h\u003e\n#include \u003cstring.h\u003e\n\ntypedef struct Seat_struct {\n    char firstName[50];\n    char lastName[50];\n    int amountPaid;\n} Seat;\n\n/*** Functions for Seat ***/\n\nvoid SeatMakeEmpty(Seat* seat) {\n    strcpy((*seat).firstName, \"empty\");\n    strcpy((*seat).lastName, \"empty\");\n    (*seat).amountPaid = 0;\n}\n\nbool SeatIsEmpty(Seat seat) {\n    return (strcmp(seat.firstName, \"empty\") == 0);\n}\n\nvoid SeatPrint(Seat seat) {\n    printf(\"%s \", seat.firstName);\n    printf(\"%s, \", seat.lastName);\n    printf(\"Paid: %d\\n\", seat.amountPaid);\n}\n/*** End functions for Seat ***/\n\n/*** Functions for array of Seat ***/\nvoid SeatsMakeEmpty(Seat seats[], int numSeats) {\n    int i;\n\n    for (i = 0; i \u003c numSeats; ++i) {\n        SeatMakeEmpty(\u0026seats[i]);\n    }\n}\n\nvoid SeatsPrint(Seat seats[], int numSeats) {\n    int i;\n\n    for (i = 0; i \u003c numSeats; ++i) {\n        printf(\"%d: \", i);\n        SeatPrint(seats[i]);\n    }\n}\n/*** End functions for array of Seat ***/\n\nint main(void) {\n    const int NUM_SEATS = 5;\n    char userKey;\n    int seatNum;\n    Seat allSeats[NUM_SEATS];\n    Seat currSeat;\n\n    userKey = '-';\n\n    SeatsMakeEmpty(allSeats, NUM_SEATS);\n\n    while (userKey != 'q') {\n        printf(\"Enter command (p/r/q): \");\n        scanf(\" %c\", \u0026userKey);\n\n        if (userKey == 'p') {  // Print seats\n            SeatsPrint(allSeats, NUM_SEATS);\n            printf(\"\\n\");\n        } else if (userKey == 'r') {  // Reserve seat\n            printf(\"Enter seat num: \");\n            scanf(\"%d\", \u0026seatNum);\n\n            if (!SeatIsEmpty(allSeats[seatNum])) {\n                printf(\"Seat not empty.\\n\\n\");\n            } else {\n                printf(\"Enter first name: \");\n                scanf(\"%s\", currSeat.firstName);\n                printf(\"Enter last name: \");\n                scanf(\"%s\", currSeat.lastName);\n                printf(\"Enter amount paid: \");\n                scanf(\"%d\", \u0026currSeat.amountPaid);\n\n                allSeats[seatNum] = currSeat;\n\n                printf(\"Completed.\\n\\n\");\n            }\n        }\n        // FIXME: Add option to delete reservations\n        else if (userKey == 'q') {  // Quit\n            printf(\"Quitting.\\n\");\n        } else {\n            printf(\"Invalid command.\\n\\n\");\n        }\n    }\n\n    return 0;\n}\n```\n\n### Derefencing a Pointer to a Struct (-\u003e)\n\n![Derefencing a Pointer to a Struct](./images/7.4%20Deferencing%20a%20Pointer%20to%20a%20Struct.png)\n\n### Seperate Files for Structs\n\n![Seperate Files for Structs](./images/7.5%20Separate%20Files%20for%20Structs.png)\n\n## Chapter 8: Pointers\n\n### Why Pointers\n\n![Why pointers](./images/8.1%20Pointers.png)\n\n### Pointer Basics\n\n![Pointer Basics](./images/8.2%20Pointer%20Basics.png)\n\n[Back to top](#table-of-contents)\n\n### Dereferencing a Pointer\n\n![Dereferencing a Pointer](./images/8.2%20Derefencing%20a%20Pointer.png)\n\n### Null Pointer\n\n![Null Pointer](./images/8.2%20Null%20Pointer.png)\n\n### Common Pointer Mistakes\n\n![Common Pointer Mistakes](./images/8.2%20Common%20Pointer%20Mistakes.png)\n\n### **Malloc Function**\n\n![Mallot and Free Functions](./images/8.3%20Mallot%20and%20Free.png)\n\n### **Free Function**\n\n![Free Function](./images/8.3%20Free%20Function.png)\n\n### Pointers with Structs\n\n![Pointers with Structs](./images/8.4%20Pointers%20with%20Structs.png)\n\n[Back to top](#table-of-contents)\n\n### String Functions with Pointers\n\n![String Functions with Pointers](./images/8.5%20String%20functions%20with%20Pointers.png)\n\n### String Searching Methods (Table)\n\n![String Searching Methods](\u003c./images/8.5%20String%20Searching%20(Table).png\u003e)\n\n### Malloc for Arrays and Strings\n\n![Malloc for Arrays and Strings](./images/8.6%20Malloc%20for%20Arrays%20and%20Strings.png)\n\n### Dynamic Copy of a String\n\n![Dynamic Copy of a String](./images/8.6%20Dynamic%20Copy%20of%20a%20String.png)\n\n- Make sure to account of the NULL character terminator in the String Length\n\n[Back to top](#table-of-contents)\n\n### Realloc Function\n\n![Realloc Function](./images/8.7%20Realloc%20Function.png)\n\n#### Dynamically Reallocating Size of an Array (Code)\n\n```c\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n\nint main(void) {\n   int* userVals = NULL; // No array yet\n   int numVals;\n   int i;\n   char userInput;\n   int userValsSum;\n   double userValsAvg;\n\n   userInput = 'c';\n\n   while (userInput == 'c') {\n\n      printf(\"Enter number of integer values: \");\n      scanf(\" %d\", \u0026numVals);\n\n      if (userVals == NULL) {\n         userVals = (int*)malloc(numVals * sizeof(int));\n      }\n      else {\n         userVals = (int*)realloc(userVals, numVals * sizeof(int));\n      }\n\n      printf(\"Enter %d integer values...\\n\", numVals);\n      for (i = 0; i \u003c numVals; ++i) {\n         printf(\"Value: \");\n         scanf(\"%d\", \u0026(userVals[i]));\n      }\n\n      // Calculate average\n      userValsSum = 0;\n      for (i = 0; i \u003c numVals; ++i) {\n         userValsSum = userValsSum + userVals[i];\n      }\n      userValsAvg = (double)userValsSum / (double)numVals;\n\n      printf(\"Average = %lf\\n\", userValsAvg);\n\n      printf(\"\\nEnter 'c' to compute another average (any other key to quit): \");\n      scanf(\" %c\", \u0026userInput);\n   }\n\n   free(userVals);\n\n   return 0;\n}\n```\n\n[Back to top](#table-of-contents)\n\n### **Vector ADT**\n\n![Vector ADT](./images/8.8%20Vector%20ADT.png)\n\n#### vector.h\n\n```c\n#ifndef VECTOR_H\n#define VECTOR_H\n\n// struct and typedef declaration for Vector ADT\ntypedef struct vector_struct {\n  int* data;\n  unsigned int size;\n} vector;\n\n// interface for accessing Vector ADT\n\n// Initialize vector\nvoid vector_create(vector* v, unsigned int vectorSize);\n\n// Destroy vector\nvoid vector_destroy(vector* v);\n\n// Resize the size of the vector\nvoid vector_resize(vector* v, unsigned int vectorSize);\n\n// Return pointer to element at specified index\nint* vector_get(vector* v, unsigned int index);\n\n// Insert new value at specified index\nvoid vector_insert(vector* v, unsigned int index, int value);\n\n// Insert new value at end of vector\nvoid vector_push_back(vector* v, int value);\n\n// Erase (remove) value at specified index\nvoid vector_remove(vector* v, unsigned int index);\n\n// Return number of elements within vector\nint vector_size(vector* v);\n\n#endif\n\n```\n\n[Back to top](#table-of-contents)\n\n#### Vector Implementation\n\n```c\n#include \"vector.h\"\n\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n\nint main(void) {\n  vector v;\n  vector_create(\u0026v, 4);\n\n  *vector_get(\u0026v, 0) = 27;\n  *vector_get(\u0026v, 1) = 44;\n  *vector_get(\u0026v, 2) = 9;\n  *vector_get(\u0026v, 3) = 17;\n\n  vector_remove(\u0026v, 1);\n  vector_remove(\u0026v, 0);\n  vector_insert(\u0026v, 0, 88);\n\n  vector_pop(\u0026v);\n\n  printf(\"Contents:\\n\");\n  for (int i = 0; i \u003c vector_size(\u0026v); ++i) {\n    printf(\"%d\\n\", *vector_get(\u0026v, i));\n  }\n\n  vector_destroy(\u0026v);\n\n  return 0;\n}\n\n// Initialize vector with specified size\nvoid vector_create(vector* v, unsigned int vectorSize) {\n  if (v == NULL)\n    return;\n\n  v-\u003edata = (int*)malloc(vectorSize * sizeof(int));\n  v-\u003esize = vectorSize;\n\n  for (int i = 0; i \u003c v-\u003esize; ++i) {\n    v-\u003edata[i] = 0;\n  }\n}\n\n// Destroy vector\nvoid vector_destroy(vector* v) {\n  if (v == NULL)\n    return;\n\n  free(v-\u003edata);\n  v-\u003edata = NULL;\n  v-\u003esize = 0;\n}\n\n// Resize the size of the vector\nvoid vector_resize(vector* v, unsigned int vectorSize) {\n  if (v == NULL)\n    return;\n\n  int oldSize = v-\u003esize;\n  v-\u003edata = (int*)realloc(v-\u003edata, vectorSize * sizeof(int));\n  v-\u003esize = vectorSize;\n\n  for (int i = oldSize; i \u003c v-\u003esize; ++i) {\n    v-\u003edata[i] = 0;\n  }\n}\n\n// Return pointer to element at specified index\nint* vector_get(vector* v, unsigned int index) {\n  if (v == NULL || index \u003e= v-\u003esize)\n    return NULL;\n\n  return \u0026(v-\u003edata[index]);\n}\n\n// Insert new value at specified index\nvoid vector_insert(vector* v, unsigned int index, int value) {\n  if (v == NULL || index \u003e v-\u003esize)\n    return;\n\n  vector_resize(v, v-\u003esize + 1);\n  for (int i = v-\u003esize - 1; i \u003e index; --i) {\n    v-\u003edata[i] = v-\u003edata[i - 1];\n  }\n\n  v-\u003edata[index] = value;\n}\n\n// Insert new value at end of vector\nvoid vector_push_back(vector* v, int value) {\n  vector_insert(v, v-\u003esize, value);\n}\n// Remove value at specified index\nvoid vector_remove(vector* v, unsigned int index) {\n  if (v == NULL || index \u003e= v-\u003esize)\n    return;\n\n  for (int i = index; i \u003c v-\u003esize - 1; ++i) {\n    v-\u003edata[i] = v-\u003edata[i + 1];\n  }\n\n  vector_resize(v, v-\u003esize - 1);\n}\n\n// Remove value at the last element\nvoid vector_pop(vector* v) {\n  if (v == NULL)\n    return;\n\n  vector_remove(v, v-\u003esize - 1);\n}\n\n// Return number of elements within vector\nint vector_size(vector* v) {\n  if (v == NULL)\n    return -1;\n\n  return v-\u003esize;\n}\n```\n\n#### **Vector Functions (Table)**\n\n![Vector Functions (Table)](\u003c./images/8.8%20Vector%20Functions%20(Table).png\u003e)\n\n#### Segmentation Fault\n\n![Segmentation Fault](./images/8.8%20Segmentation%20Fault.png)\n\n### LinkedList vs. Vector\n\n![LinkedList vs. Vector](./images/8.9%20LinkedList%20vs.%20Vector.png)\n\n[Back to top](#table-of-contents)\n\n#### LinkedList (Code)\n\n```c\n\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n\ntypedef struct IntNode_struct {\n  int dataVal;\n  struct IntNode_struct* nextNodePtr;\n} IntNode;\n\n// Constructor\nvoid IntNode_Create(IntNode* thisNode, int dataInit, IntNode* nextLoc) {\n  thisNode-\u003edataVal = dataInit;\n  thisNode-\u003enextNodePtr = nextLoc;\n}\n\n/* Insert newNode after node.\n Before: thisNode -- next\n After:  thisNode -- newNode -- next\n */\nvoid IntNode_InsertAfter(IntNode* thisNode, IntNode* newNode) {\n  IntNode* tmpNext = NULL;\n\n  tmpNext = thisNode-\u003enextNodePtr;  // Remember next\n  thisNode-\u003enextNodePtr = newNode;  // this -- new -- ?\n  newNode-\u003enextNodePtr = tmpNext;   // this -- new -- next\n}\n\n// Print dataVal\nvoid IntNode_PrintNodeData(IntNode* thisNode) {\n  printf(\"%d\\n\", thisNode-\u003edataVal);\n}\n\n// Grab location pointed by nextNodePtr\nIntNode* IntNode_GetNext(IntNode* thisNode) {\n  return thisNode-\u003enextNodePtr;\n}\n\nint main(void) {\n  IntNode* headObj = NULL;  // Create IntNode objects\n  IntNode* nodeObj1 = NULL;\n  IntNode* nodeObj2 = NULL;\n  IntNode* nodeObj3 = NULL;\n  IntNode* currObj = NULL;\n\n  // Front of nodes list\n  headObj = (IntNode*)malloc(sizeof(IntNode));\n  IntNode_Create(headObj, -1, NULL);\n\n  // Insert nodes\n  nodeObj1 = (IntNode*)malloc(sizeof(IntNode));\n  IntNode_Create(nodeObj1, 555, NULL);\n  IntNode_InsertAfter(headObj, nodeObj1);\n\n  nodeObj2 = (IntNode*)malloc(sizeof(IntNode));\n  IntNode_Create(nodeObj2, 999, NULL);\n  IntNode_InsertAfter(nodeObj1, nodeObj2);\n\n  nodeObj3 = (IntNode*)malloc(sizeof(IntNode));\n  IntNode_Create(nodeObj3, 777, NULL);\n  IntNode_InsertAfter(nodeObj1, nodeObj3);\n\n  // Print linked list\n  currObj = headObj;\n  while (currObj != NULL) {\n    IntNode_PrintNodeData(currObj);\n    currObj = IntNode_GetNext(currObj);\n  }\n\n  return 0;\n}\n```\n\n### **Memory Regions - Heap and Stack (Table)**\n\n![Memory Regions - Heap and Stack (Table)](\u003c./images/8.10%20Memory%20Regions%20-%20Heap%20and%20Stack%20(Table).png\u003e)\n\n### Memory Leaks\n\n![Memory Leaks](./images/8.12%20Memory%20Leaks.png)\n\n[Back to top](#table-of-contents)\n\n## **Chapter 9: Input and Output**\n\n### File Pointer: stdout (fprintf)\n\n![File Buffer](./images/9.1.1%20File%20Pointers.png)\n\n### File Pointer: stdin (fscanf)\n\n![std in](./images/9.1.1%20std%20in.png)\n\n### Formatted Output (Table)\n\n![formatted output](./images/9.2.1%20Formated%20Output.png)\n\n#### Integer Formatting\n\n![Integer Formatting](./images/9.2.2%20Integer%20Formatting.png)\n\n[Back to top](#table-of-contents)\n\n#### String Formatting\n\n![String Formatting](./images/9.2.3%20String%20Formatting.png)\n\n### Flushing Output (fflush)\n\n![Flusing Output](./images/9.2.4%20Flushing%20Ouput.png)\n\n### **Input Parsing**\n\n![9.3.1 Input Parsing](./images/9.3.1%20Formatted%20Input.png)\n\n#### Input Validation\n\n![Input Validation](./images/9.3.2%20Input%20Validation.png)\n\n[Back to top](#table-of-contents)\n\n### Parsing Input String (sscanf)\n\n![Parsing Input String (sscanf)](\u003c./images/9.3.4%20Parsing%20Input%20String%20(sscanf).png\u003e)\n\n#### Parsing Input (sscanf and fgets) Example\n\n![Parsing Input (sscanf and fgets) Example](./images/9.3.5%20Sscanf.png)\n\n### **File Input and Output**\n\n![File Input and Output](./images/9.4.1%20File%20Input%20and%20Output.png)\n\n#### **Writting to Files (fopen)**\n\n![Writting to Files (fopen)](./images/9.4.2%20Writting%20to%20Files.png)\n\n[Back to top](#table-of-contents)\n\n### **Parsing Through an Entire File (!feof)**\n\n![Parsing Through an Entire File (!feof)](\u003c./images/9.4.3%20Parsing%20Though%20A%20File%20(!feof).png\u003e)\n\n### Binary Files\n\n![Binary Files](./images/9.5.1%20Binary%20Files.png)\n\n#### Writting to a Binary Files\n\n![Writting to a Binary Files](./images/9.5.3%20Writting%20to%20a%20Binary%20File.png)\n\n#### Reading from a Binary File\n\n![Reading from a Binary File](./images/9.5.2%20Reading%20from%20A%20binary%20File.png)\n\n[Back to top](#table-of-contents)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebastian-nunez%2Fsystems-programming","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsebastian-nunez%2Fsystems-programming","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebastian-nunez%2Fsystems-programming/lists"}