Code Monkey home page Code Monkey logo

printf_demo's Introduction

Welcome to Printf Demo


Task

This project replicates the printf() C standard library function to understand its inner workings.

Description

The development of this command-line application is broken down into two major parts:

  1. 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)
  2. Helper functions such as changing decimal numbers into octal or hexadecimal formats

Installation

Steps:

  1. You can download the project folder and files manually to your computer or fork the Github repo at: https://github.com/Ranada/printf_demo
  2. Or through your terminal, clone this repository: git clone https://github.com/Ranada/printf_demo
  3. Go to the directory containing this project: cd printf_demo
  4. 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)
  5. Compile automatically using the included makefile using make or manually gcc -Wall -Wextra -Werror *.c -o run_test

Usage

  1. 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.
  2. Compile automatically using the included makefile using make or manually gcc -Wall -Wextra -Werror *.c -o run_test
  3. 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

Screenshot of expected command line output from using test_cases.c

Takeaways and Lessons Learned

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.

Final thoughts

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.

Have recommendations? Want to chat about programming and other good stuff? Let's connect.

[email protected]
https://www.linkedin.com/in/neilranada/

The Core Team

Neil Ranada, Software Engineer

Made at Qwasar Silicon Valley Qwasar Silicon Valley Logo

printf_demo's People

Contributors

ranada avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.