This project replicates the printf()
C standard library function to understand its inner workings.
The development of this command-line application is broken down into two major parts:
- Primary functions for converting various data types (character, string, signed integer, unsigned integer, octal, hexadecimal, memory address) based on their associated flags in the C language (
%c
,%s
,%d
,%u
,%o
,%x
,%p
) - Helper functions such as changing decimal numbers into octal or hexadecimal formats
Steps:
- You can download the project folder and files manually to your computer or fork the Github repo at: https://github.com/Ranada/printf_demo
- Or through your terminal, clone this repository:
git clone https://github.com/Ranada/printf_demo
- Go to the directory containing this project:
cd printf_demo
- Check to see if you have a GCC compiler installed:
gcc --version
(if not installed, consider using Homebrew method: https://formulae.brew.sh/formula/gcc) - Compile automatically using the included makefile using
make
or manuallygcc -Wall -Wextra -Werror *.c -o run_test
- Use the
test_cases.c
file included with this project. Or add your C file with test functions and include#include "printf_demo.h"
and#include <stdio.h>
at the top of your file. - Compile automatically using the included makefile using
make
or manuallygcc -Wall -Wextra -Werror *.c -o run_test
- Run the program
./run_test
Note: If you receive error messages for one or more of your test cases, comment out //
the test function(s) in question and then try to compile with make
and run the program again ./run_test
I learned the printf function in the C library handles numerous conversions of various data types (integer, character, string, memory address) "under the hood" before printing to the command line. Before printing, some math is required to convert from decimal to octal or hexadecimal formats.
After completing this C project, I find using librarian functions and methods in higher-level programming languages such as Javascript and Ruby less mysterious. I'm more comfortable looking up documentation to understand these built-in solutions.
[email protected]
https://www.linkedin.com/in/neilranada/
Neil Ranada, Software Engineer
Made at Qwasar Silicon Valley