betty passes, write + 1, NO RETURN _PRTINF PLS
This commit is contained in:
18
printf.c
18
printf.c
@@ -2,7 +2,6 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _printf - printf but worse
|
* _printf - printf but worse
|
||||||
* @format: format string
|
* @format: format string
|
||||||
@@ -11,24 +10,21 @@
|
|||||||
**/
|
**/
|
||||||
int _printf(const char *format, ...)
|
int _printf(const char *format, ...)
|
||||||
{
|
{
|
||||||
int buff_idx, fmt_idx;
|
int buff_idx = 0;
|
||||||
unsigned int identifiers, BUFF_SIZE;
|
int fmt_idx = 0;
|
||||||
|
unsigned int identifiers = _contains(format, '%');
|
||||||
|
unsigned int BUFF_SIZE = _strlen(format) - (identifiers * 2);
|
||||||
char *buffer, *next;
|
char *buffer, *next;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
|
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
identifiers = _contains(format, '%');
|
|
||||||
BUFF_SIZE = _strlen(format) - (identifiers * 2);
|
|
||||||
buffer = malloc(BUFF_SIZE);
|
buffer = malloc(BUFF_SIZE);
|
||||||
|
|
||||||
if (!format) /* No string. No laundry */
|
if (!format) /* No string. No laundry */
|
||||||
return (0);
|
return (0);
|
||||||
buff_idx = 0;
|
|
||||||
fmt_idx = 0;
|
|
||||||
while (*(format + fmt_idx))
|
while (*(format + fmt_idx))
|
||||||
{
|
{
|
||||||
if ((*format == '%') && (*(format + 1))) /*hello %s*/
|
if ((*(format + fmt_idx) == '%') && (*(format + fmt_idx + 1)))
|
||||||
{
|
{
|
||||||
switch (*(format + 1)) /*this needs to shrink*/
|
switch (*(format + 1)) /*this needs to shrink*/
|
||||||
{
|
{
|
||||||
@@ -38,7 +34,6 @@ int _printf(const char *format, ...)
|
|||||||
BUFF_SIZE = _strlen(buffer);
|
BUFF_SIZE = _strlen(buffer);
|
||||||
buff_idx += _strlen(next);
|
buff_idx += _strlen(next);
|
||||||
fmt_idx += 2;
|
fmt_idx += 2;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'c': /* add 1 byte and i++ */
|
case 'c': /* add 1 byte and i++ */
|
||||||
break;
|
break;
|
||||||
@@ -53,7 +48,6 @@ int _printf(const char *format, ...)
|
|||||||
fmt_idx++;
|
fmt_idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
write(1, buffer, BUFF_SIZE + 1);
|
||||||
write(1, buffer, BUFF_SIZE);
|
|
||||||
return (_strlen(buffer));
|
return (_strlen(buffer));
|
||||||
}
|
}
|
||||||
|
|||||||
3
strcpy.c
3
strcpy.c
@@ -23,8 +23,5 @@ char *_strcpy(char *dest, char *src)
|
|||||||
*(new_me + s_idx++) = *(src + i);
|
*(new_me + s_idx++) = *(src + i);
|
||||||
*(new_me + _strlen(new_me)) = '\0';
|
*(new_me + _strlen(new_me)) = '\0';
|
||||||
|
|
||||||
free(dest);
|
|
||||||
|
|
||||||
|
|
||||||
return (new_me);
|
return (new_me);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,11 @@
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
char *test_0 = "Hej";
|
char *test_0 = "Hej";
|
||||||
|
char *test_1 = "pls";
|
||||||
/*
|
/*
|
||||||
* Brain ded to think bout test cond
|
* Brain ded to think bout test cond
|
||||||
*/
|
*/
|
||||||
_printf("%s \n", test_0);
|
_printf("%s\n%s\n", test_0, test_1);
|
||||||
return (_printf("hey, %s", test_0));
|
return (0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user