Git Product home page Git Product logo

printf's Introduction

_printf() in the C Programming Language

This project is about recreating the C library function printf. The function printf sends formatted output to stdout (standard output stream) by formatting the argument(s) passed in and converting the arguments(s) into a character string. This version will be used as _printf.

Environment

Our printf has been tested on Ubuntu 14.05.5 LTS

Tests done in VirtualBox on Ubuntu via Vagrant(1.9.1)

Repository Breakdown

Once cloned over, the repository will contain the following files:

File Decription
holberton.h header file with prototypes
printf.c contains main printf function
_putchar.c contains putchar function
string_specifiers.c contains functions for s and c
string_spec_helpers.c contains functions to help with string functions in string_specifiers.c
signed_decimal_specifiers.c contains functions for d and i
unsigned_specifiers.c contains functions for o, u, x, X
binary_specifier.c contains functions for b
pointer_address_specifiers.c contains functions for p
write_percent specifiers.c contains functions for '%'
write_buffer.c contains functions to write to the buffer
reset_buffer.c contains functions to reset the buffer
rev_string.c contains functions to reverse strings
rot_13.c contains functions to converts a string to rot13 format

Format tags

Format tags implemented in _printf

specifier output
c characters
s string of characters
d or i int to signed decimal
o unsigned int to unsigned octal
u unsigned int to unsigned decimal
x or X unsigned int to unsigned hexadecimal
p pointer address
% no conversion, writes '%'
r reverses string input
R converts string input into rot13

How to Use

There are two ways to use the _printf function in your code. First step is to clone the repository into your directory

$ git clone https://github.com/kjowong/printf.git

Once that is done, you can create a static library or use the -I in gcc

Compile with a static library for _printf

Change your directory into the _printf directory in order to create your static library

$ cd printf

Compile all the .c files in _printf

gcc -Wall -Werror -Wextra -pedantic -c *.c

All your .c files should also have a corresponding .o file. Run the following to create your static library:

ar -rc lib<LIBRARY-NAME>.a *.o

To run your static library with your own YOUR-FILE.c file, use the following command:

gcc <YOUR-FILE>.c -L. -lib<LIBRARY-NAME> -o <OUT-NAME>

Compile without a static library for _printf

Make sure the _printf directory is in the same directory as your YOUR-FILE.c file and then run the following command:

gcc -Wall -Werror -Wextra -pedantic -I $PWD/printf prinft/*.c <YOUR-FILE>.c

The -I flag allows you to include the directory of the header file holberton.h. $PWD/printf takes the absolute path of the _print directory while printf/*.c compiles all your .c files in _printf

Use in code

How to use _printf in your code

Please see the following example when _printf is implemented in your code:

#include <holberton.h>

int main(void)
{
  _printf("Let's try to print a %s sentence.\n", "simple");
  return (0):
 }

This is an an example output:

$ Let's try to print a simple sentence.

Notes

This _printf function currently does not support special flags [+ , - , `, \0 , #], field, width or precision.

Known Bugs

There are no known bugs at the time.

Authors

Kimberly Wong - Github || Twitter || email

Lisa Leung - Github || Twitter || email

Feedback and contributors welcomed. Reach out to either authors.

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.