Skeleton %s

This commit is contained in:
2023-08-20 17:45:17 +03:00
parent 64070c8152
commit cc9901e281

View File

@@ -3,34 +3,73 @@
int _printf(const char *format, ...) int _printf(const char *format, ...)
{ {
/* For any Iterative Operation */
int i = 0; int i = 0;
int BUFF_SIZE = _strlen(format);
unsigned int identifiers; /* how many %* that aren't %% */
va_list args;
BUFF_SIZE = _strlen(format); /* how many %* that aren't %% */
unsigned int identifiers;
char* buffer[BUFF_SIZE];
/* Number of Identifiers */ /* Number of Identifiers */
identifiers = _contains(format, '%'); identifiers = _contains(format, '%');
/* Primary Buffer Size */
int BUFF_SIZE = _strlen(format) - (identifiers * 2);
/* Instantiating Buffer */
char* buffer[BUFF_SIZE];
/* Shoving args in list */
va_list args;
va_start(args, format); va_start(args, format);
/* If string is nonexist, die */
if (!format) if (!format)
return (0); return (0);
/* While string is alive or smth*/
while(format) while(format)
{ {
if (*format == '%') /* Detecting identifier in code
* whilst ensuring next char exists
*/
if ((*format == '%') && (*(format + 1) != '\0'))
{ {
/* Handling depending on char after identifier*/
switch (*(format + 1)) switch (*(format + 1))
{ {
case 's': case 's':
/* Something _strlen() string arg, realloc
* Increment i by strlen or smth
*/
/* Trying to get length of passed string */
int pass_str_len = _strlen(va_arg(args, char*));
/* Incrememnting buffersize to fit new string*/
BUFF_SIZE += pass_str_len;
/* Shoving str values into buffer*/
/* Realloc? pls review*/
free(buffer);
buffer = malloc(BUFF_SIZE * sizeof(char));
/* Incrementing iterator i by string length
* So we'd be able to insert at proper
* index in buffer
*/
i += pass_str_len;
break; break;
case 'c': case 'c':
/* Something add 1B to buffer and realloc
* Increment i by 1
*/
break; break;
case '%': case '%':
/* Something add 1B, shove %, realloc
* increment i by 1
*/
break; break;
} }
/* /*
@@ -42,7 +81,7 @@ int _printf(const char *format, ...)
else else
{ {
/* ERROR SCREAMING AT ME PLS HELP */ /* ERROR SCREAMING AT ME PLS HELP */
*(buffer + i) = (format + i); *(buffer + i) = (char *)(format + i);
i++; i++;
} }
} }