29#define INT_MAX_LENGTH 10
30#define PRECISION_FOR_FLOAT 8
51 for (
int i = 1; i <= a; ++i)
64 return (*c >=
'0' && *c <=
'9') ? 1 : 0;
117 char *buf = (
char *)
malloc(
sizeof(
char) + 1);
180 if (width > 0 && size < width)
181 for (
int i = 0; i < (width - precision); ++i)
184 if (precision > 0 && precision > size)
185 for (
int i = 0; i < (precision - size); ++i)
213 int reqd_blanks = width - (precision + 1) - ndigits;
222 dval = dval - (int) dval;
255 if (precision != 0 && precision < size)
259 for (
int i = 0; i < (width - size); ++i)
263 for (
int i = 0; i < size; ++i)
283 *width = *width * 10 + (*p++ -
'0');
288 *precision = *precision * 10 + (*p -
'0');
312 for (p = fmt; *p !=
'\0'; ++p) {
329 ival = va_arg(ap,
int);
333 cval = va_arg(ap,
int);
337 dval = va_arg(ap,
double);
341 precision = PRECISION_FOR_FLOAT;
345 sval = va_arg(ap,
char *);
#define malloc(bytes)
This macro replace the standard malloc function with malloc_dbg.
Definition malloc_dbg.h:18
#define free(ptr)
This macro replace the standard free function with free_dbg.
Definition malloc_dbg.h:26
void print_int_value(int n, int width, int precision)
Definition min_printf.h:158
void min_printf(char *fmt,...)
min_printf is the function same as printf
Definition min_printf.h:299
char get_ch(char *p, Buffer *buffer)
Returns specific required next character.
Definition min_printf.h:74
void print_double_value(double dval, int width, int precision)
The algorithm here is also the same as the print_int_value function.
Definition min_printf.h:210
int power_of_ten(int a)
Definition min_printf.h:48
void reverse_str(char *p)
Reverses a string using two pointer algorithm
Definition min_printf.h:128
char * get_width_and_precision(char *p, Buffer *buffer, int *width, int *precision)
Takes width and precision specified from the format of the string.
Definition min_printf.h:275
void unget_ch(char *c, Buffer *buffer)
Stores character to the buffer->buffr_char
Definition min_printf.h:88
#define INT_MAX_LENGTH
for malloc and free functions
Definition min_printf.h:29
struct buffer Buffer
struct used to store character in certain times
void put_char(char s)
Prints one character on screen.
Definition min_printf.h:114
int is_number(char *c)
Checks if a character is a number.
Definition min_printf.h:62
int get_number_of_digits(int n)
Calculates the number of digits in a number.
Definition min_printf.h:100
void print_string(char *p, int width, int precision)
Definition min_printf.h:238
struct used to store character in certain times
Definition min_printf.h:35