yes
This commit is contained in:
14
printf.c
14
printf.c
@@ -11,7 +11,7 @@
|
||||
**/
|
||||
int _printf(const char *format, ...)
|
||||
{
|
||||
int buff_idx;
|
||||
int buff_idx, fmt_idx;
|
||||
unsigned int identifiers, BUFF_SIZE;
|
||||
char *buffer, *next;
|
||||
va_list args;
|
||||
@@ -25,7 +25,8 @@ int _printf(const char *format, ...)
|
||||
if (!format) /* No string. No laundry */
|
||||
return (0);
|
||||
buff_idx = 0;
|
||||
while (format)
|
||||
fmt_idx = 0;
|
||||
while (*(format + fmt_idx))
|
||||
{
|
||||
if ((*format == '%') && (*(format + 1))) /*hello %s*/
|
||||
{
|
||||
@@ -34,7 +35,9 @@ int _printf(const char *format, ...)
|
||||
case 's':
|
||||
next = va_arg(args, char*); /*Store string temporarily*/
|
||||
buffer = _strcpy(buffer, next);
|
||||
BUFF_SIZE += _strlen(buffer);
|
||||
BUFF_SIZE = _strlen(buffer);
|
||||
buff_idx += _strlen(next);
|
||||
fmt_idx += 2;
|
||||
|
||||
break;
|
||||
case 'c': /* add 1 byte and i++ */
|
||||
@@ -45,11 +48,12 @@ int _printf(const char *format, ...)
|
||||
}
|
||||
else
|
||||
{
|
||||
*(buffer + buff_idx) = *(format + buff_idx);
|
||||
*(buffer + buff_idx) = *(format + fmt_idx);
|
||||
buff_idx++;
|
||||
fmt_idx++;
|
||||
}
|
||||
}
|
||||
|
||||
write(1, &buffer, BUFF_SIZE);
|
||||
write(1, buffer, BUFF_SIZE);
|
||||
return (_strlen(buffer));
|
||||
}
|
||||
|
||||
2
strcpy.c
2
strcpy.c
@@ -23,6 +23,8 @@ char *_strcpy(char *dest, char *src)
|
||||
*(new_me + s_idx++) = *(src + i);
|
||||
*(new_me + _strlen(new_me)) = '\0';
|
||||
|
||||
free(dest);
|
||||
|
||||
|
||||
return (new_me);
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ int main(void)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = _printf("Hello world");
|
||||
len = _printf("Hello world\n");
|
||||
return (len);
|
||||
}
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char test_0[] = "Hej";
|
||||
char *test_0 = "Hej";
|
||||
/*
|
||||
* Brain ded to think bout test cond
|
||||
*/
|
||||
return (_printf("%s", test_0));
|
||||
_printf("%s \n", test_0);
|
||||
return (_printf("hey, %s", test_0));
|
||||
|
||||
}
|
||||
|
||||
3
tests/test.sh
Executable file
3
tests/test.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/bash
|
||||
gcc -Wall -pedantic -Werror -Wextra -std=gnu89 $1 ../*.c -o a
|
||||
./a
|
||||
Reference in New Issue
Block a user