Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions _printf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include main.h
/**
*_printf - printf
*@format: const char pointer
*Description: this functions implement some functions of printf
*Return: num of characters printed
*/
int _printf(const char *format, ...)
{
const char *string;
int cont = 0;
va_list arg;

if (!format)
return (-1);

va_start(arg, format);
string = format;

cont = loop_format(arg, string);

va_end(arg);
return (cont);
}
/**
*loop_format - loop format
*@arg: va_list arg
*@string: pointer from format
*Description: This function make loop tp string pointer
*Return: num of characters printed
*/

int loop_format(va_list arg, const char *string)
{
int i = 0, flag = 0, cont_fm = 0, cont = 0, check_per = 0;

while (i < _strlen((char *)string) && *string != '\0')
{
char aux = string[i];

if (aux == '%')
{
i++, flag++;
aux = string[i];
if (aux == '\0' && _strlen((char *)string) == 1)
return (-1);
if (aux == '\0')
return (cont);
if (aux == '%')
{
flag++;
} else
{
cont_fm = function_manager(aux, arg);
if (cont_fm >= 0 && cont_fm != -1)
{
i++;
aux = string[i];
if (aux == '%')
flag--;
cont = cont + cont_fm;
} else if (cont_fm == -1 && aux != '\n')
{
cont += _putchar('%');
}
}
}
check_per = check_percent(&flag, aux);
cont += check_per;
if (check_per == 0 && aux != '\0' && aux != '%')
cont += _putchar(aux), i++;
check_per = 0;
}
return (cont);
}
/**
* check_percent - call function manager
*@flag: value by reference
*@aux: character
*Description: This function print % pear
*Return: 1 if % is printed
*/
int check_percent(int *flag, char aux)
{
int tmp_flag;
int cont = 0;

tmp_flag = *flag;
if (tmp_flag == 2 && aux == '%')
{
_putchar('%');
tmp_flag = 0;
cont = 1;
}
return (cont);
}

/**
* call_function_manager - call function manager
*@aux: character parameter
*@arg: va_list arg
*Description: This function call function manager
*Return: num of characteres printed
*/

int call_function_manager(char aux, va_list arg)
{
int cont = 0;

cont = function_manager(aux, arg);
return (cont);
}
13 changes: 0 additions & 13 deletions main.h

This file was deleted.