-
Notifications
You must be signed in to change notification settings - Fork 0
/
0-task.c
37 lines (32 loc) · 1.02 KB
/
0-task.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "main.h"
int _printf(const char *format, ...) {
va_list args;
va_start(args, format);
int count = 0; // Count of characters printed
while (*format != '\0') {
if (*format == '%') {
format++; // Move past '%'
switch (*format) {
case 'c':
count += putchar(va_arg(args, int));
break;
case 's':
count += printf("%s", va_arg(args, char*));
break;
case '%':
count += putchar('%');
break;
default:
// Invalid specifier, just print the character
count += putchar('%');
count += putchar(*format);
break;
}
} else {
count += putchar(*format);
}
format++; // Move to the next character in format
}
va_end(args);
return count;
}