Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.8 kB
3
Indexable
Never
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>

void (*fun_ptr_arr[172])(char *arg, va_list paramsInfos, char *exceed, int index);

int my_strlen(const char *str) {
    if (str == NULL)
        return 0;
    for (int idx = 0; str != '\0'; idx += 1) {
        if (str[idx] == '\0')
            return idx;
    }
    return 0;
}

char *my_strstr(char *str, char *to_find) {
  int i = 0;

  if (str[0] != '\0') {
        i = 0;
    while (to_find[i] != '\0') {
        if (to_find[i] != str[i])
            return (my_strstr(str + 1, to_find));
        i = i + 1;
    }
        return (str);
    }
    return 0;
}

char *extract_flag(char *str) {
    char *flags[] = {"%lld", "%%", "%d", "%i", "%o", "%u", "%x", "%a", "%e", "%f",
    "%g", "%c", "%s", "%p", "%n", NULL};

    for (int idx = 0; flags[idx] != NULL; idx += 1) {
        if (my_strstr(str, flags[idx]))
            return flags[idx];
    }
}

void string() {
    // print string pour pas oublier pour moi
}

void dictionary(void)
{
	fun_ptr_arr[(int)('s')] = string;
}

int my_printf(char *format, ...) {
    char okko[] = "J'ai %d ans, mais %s veux pas le reconnaitre, je travailler %lldcomme convenu";
    char *flag;
    char *token;
    int meet_a_flag = 0;

    va_list paramsInfos;
    va_start(paramsInfos, format);

    dictionary();

    token = strtok(okko, " \t\r\n\v\f");

    for (; token != NULL;) {
        if (my_strstr(token, "%")) {
            flag = extract_flag(token);
            print_entries[(int)arg[index]](flag, paramsInfos);
            meet_a_flag += 1;
        }
        token = strtok(NULL, " \t\r\n\v\f");
    }
    va_end(paramsInfos);
    return 0;
}

int main() {
    my_printf("wsh alors,okok", 18, "Loic", 12345678987654345);
    return 0;
}