void test_striteri(void) { char a[20]; ft_strcpy(a, "hello my name is"); ft_striteri(a, to_upper2); if (ft_strcmp("HELLO MY NAME IS", a) != 0) ft_putendl("ERROR: ft_striteri failed."); ft_striteri(NULL, to_upper2); ft_putendl("OK: ft_striteri passed."); ft_putendl("---------"); }
int main(void) { /* striter */ ft_putendl("--- striter ? --- "); char str[] = "abcde"; ft_striter(str, ft_change); /* striteri */ ft_putendl("--- striter ? --- "); char str2[] = "abcde"; ft_striteri(str2, ft_change2); /* strmap */ ft_putendl("--- strmap ? --- "); char str3[] = "abcde"; ft_putendl(ft_strmap(str3, ft_change3)); /* strmapi */ ft_putendl("--- strmapi ? --- "); char str4[] = "abcde"; ft_putendl(ft_strmapi(str4, ft_change4)); return (0); }
void test_striteri() { char tmp[] = "M**********r"; dprintf(1, "Striteri "); ft_striteri(tmp, &char_to_index); if (strcmp(tmp, "012345678901") != 0) { dprintf(1, "\x1b[31mFail\x1b[0m\n Params:\n s : M**********r\n f : char_to_index(unsigned int index, char *c)\n *c = i modulo 10 + 48;\n\n Valeur attendue : 012345678901\n Valeur obtenue : %s\n", tmp); return; } dprintf(1, "\x1b[32mOK\x1b[0m\n"); }
char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) { char *newstr; if (s && *f) { newstr = ft_strdup(s); ft_striteri((char*)s, (void(*)(unsigned int, char*))f); return (newstr); } return (0); }
void test_striteri() { void (*f)(unsigned int, char*); char ptr[20] = "bonjour"; f = &test_striteri_1; ft_striteri(ptr, f); ft_putstr("TEST STRITERI : "); if (!strcmp(ptr, "bnlgkpl")) ft_putendl("ok :)"); else ft_putendl("not ok :("); }