Skip to content

aabdumalikov/arc-01-my_printf

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

arc-01-my_printf

My Printf

Remember to git add && git commit && git push each exercise!

We will execute your function with our test(s), please DO NOT PROVIDE ANY TEST(S) in your file

For each exercise, you will have to create a folder and in this folder, you will have additional files that contain your work. Folder names are provided at the beginning of each exercise under submit directory and specific file names for each exercise are also provided at the beginning of each exercise under submit file(s).


My Printf
Submit directory .
Submit file my_printf.c

Description

NAME

int my_printf(char * restrict format, ...);

Prolog

The very first thing we do when learning a programming language is to write "Hello World !" on the screen. Well guess what ? This custom comes from a notebook called ... Programming in C: A Tutorial !

Unfortunately for you, this project will bring you back in the 1970s, before the existence of this book, and you will have to write your own function to greet the world.

Fortunately for you, you will strengthen your programming skills and learn new programming concepts: variadic functions and variable argument lists. Recoding printf is also a good exercise to learn to have a well structured code organisation. Modularity is the key here since printf has a lot of different options that you will have to recode yourself. Adding a new option feature should be easy and smooth if the code is well designed !

DESCRIPTION

The my_printf() function produce output according to a format as described below. The my_printf() functions write output to stdout, the standard output stream;

This function writes the output under the control of a format string that specifies how subsequent arguments (or arguments accessed via the variable-length argument facilities of stdarg(3)) are converted for output.

The format string is composed of zero or more directives: ordinary characters (not PERCENT), which are copied unchanged to the output stream; and conversion specifications, each of which results in fetching zero or more subsequent arguments.

Each conversion specification is introduced by the PERCENT character. The arguments must correspond properly (after type promotion) with the conversion specifier. After the PERCENT, the following appear in sequence:

  • doux The int (or appropriate variant) argument is converted to signed decimal (d). unsigned octal (o), unsigned decimal (u), unsigned hexadecimal (x).
  • c The int argument is converted to an unsigned char, and the resulting character is written.
  • s The char * argument is expected to be a pointer to an array of character type (pointer to a string). Characters from the array are written up to (but not including) a terminating NUL character.
  • p The void * pointer argument is printed in hexadecimal.

Requirements

  • Your code must be compiled with the flags -Wall -Wextra -Werror.

Hint(s)

  • • man printf

  • • man 3 stdarg

  • • Watch out for memory leaks !

  • • You can test your code against memory errors by compiling with the debugging flags -g3 -fsanitize=address

  • Global variables are strictly FORBIDDEN

  • Static variables are strictly FORBIDDEN

Authorized function(s)

  • • write(2)
  • • malloc
  • • free
  • • va_start, va_arg, va_copy, va_end (see man 3 stdarg)

(Obvious) Unauthorized functions

  • printf and co. (fprintf, sprintf, snprintf, asprintf, dprintf, vprintf, vfprintf, vsprintf, vsnprintf, vasprintf, vdprintf)
  • Multiline macros are forbidden
  • Include another .c is forbidden
  • Macros with logic (while/if/variables/...) are forbidden

Epilog

Good luck!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published