Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- void test_strcmp(char *str, char *str2)
- {
- printf("strcmp(%s, %s) = %i\n", str, str2, strcmp(str, str2));
- }
- void test_strncmp(char *str, char *str2, int size)
- {
- printf("strncmp(%s, %s, %i) = %i\n", str, str2, size, strncmp(str, str2, size));
- }
- void test_strcasecmp(char *str, char *str2)
- {
- printf("strcasecmp(%s, %s) = %i\n", str, str2, strcasecmp(str, str2));
- }
- void test_strchr(char *str, int c)
- {
- printf("strchr(%s, %c) = %s\n", str, c, strchr(str, c));
- }
- void test_rindex(char *str, int c)
- {
- printf("rindex(%s, %c) = %s\n", str, c, rindex(str, c));
- }
- void test_strstr(char *str, char *str2)
- {
- strstr(str, str2);
- printf("strstr(%s, %s) = %s\n", str, str2, strstr(str, str2));
- }
- int main(int ac, char **av) {
- char *str = calloc(1024, 1);
- void *ptr = str;
- strcpy(str, "sahel est vraiment trop fort");
- size_t len = strlen(str);
- printf("len: %lu\n", len);
- for (size_t i = 0;i<10000;i++)
- test_strchr(str, i);
- test_strchr("", 0);
- test_strchr("", 'z');
- for (size_t i = 0;i<10000;i++)
- test_rindex(str, i);
- test_rindex("", 0);
- test_rindex("", 'z');
- char *save = memset(NULL, 0, 0);
- printf("memset null: %p\n", save);
- printf("memset (%%i): ");
- fflush(stdout);
- len = strlen(str);
- str = memset(str, '0', len);
- write(1, str, len);
- printf("\n");
- save = memcpy(NULL, NULL, 0);
- printf("memcpy null: %p\n", save);
- str = memcpy(str, "Sahel est vraiment trop fort", 28);
- printf("strcpy: %s\n", str);
- test_strcmp("abcdef", "abcdef");
- test_strcmp("abcdef", "000bcdef");
- test_strcmp("abcdef", "");
- test_strcmp("", "abcdef");
- test_strcmp("", "");
- test_strcmp("abcdef", "a");
- //memset(str, 0, 1024);
- fflush(stdout);
- str = memmove(str, str + 4, strlen(str + 4));
- printf("1memmove: %s\n", str);
- str = memmove(str + 4, str, strlen(str));
- printf("2memmove: %s\n", str);
- fflush(stdout);
- test_strncmp("abcdef", "abcdf", 4);
- test_strncmp("abcdef", "abcdf", 5);
- test_strncmp("abcdef", "abcdf", 0);
- test_strncmp(NULL, "", 0);
- test_strncmp("", NULL, 0);
- test_strncmp(NULL, NULL, 0);
- test_strcasecmp("ABCDEF", "ABCDEF");fflush(stdout);
- test_strcasecmp("ABCDEF", "abcdef");fflush(stdout);
- test_strcasecmp("", "ABCDEF");fflush(stdout);
- test_strcasecmp("", "");fflush(stdout);
- test_strstr("", "");
- test_strstr(str, "");
- test_strstr("", str);
- test_strstr(str, "V");
- test_strstr(str, "m");
- test_strstr(str, "cent");
- test_strstr(str, "est");
- test_strstr(str, "estz");
- test_strstr(str, "fort\0z");
- test_strstr("Un test incoryable!", "Un test incoryable!");
- fflush(stdout);
- printf("1strpbrk: %s\n", strpbrk(str, "a"));
- printf("2strpbrk: %s\n", strpbrk(str, "ze"));
- printf("3strpbrk: %s\n", strpbrk(str, "zzz"));
- printf("4strpbrk: %s\n", strpbrk(str, "cent"));
- printf("5strpbrk: %s\n", strpbrk(str, "e"));
- printf("6strpbrk: %s\n", strpbrk(str, ""));
- printf("7strpbrk: %s\n", strpbrk("", ""));
- fflush(stdout);
- printf("8strpbrk: %s\n", strpbrk(NULL, ""));
- //printf("8strpbrk: %s\n", strpbrk(NULL, NULL));
- fflush(stdout);
- printf("1strcspn %lu\n", strcspn(str, "Vincent"));
- printf("2strcspn %lu\n", strcspn(str, "bonjour je "));
- printf("3strcspn %lu\n", strcspn(str, "abcdefghijklmnoqrstuvwxyz "));
- printf("4strcspn %lu\n", strcspn(str, "a"));
- printf("5strcspn %lu\n", strcspn(str, "lolqsd"));
- printf("6strcspn %lu\n", strcspn(str, ""));
- printf("7strcspn %lu\n", strcspn("", "as"));
- printf("7strcspn %lu\n", strcspn("Je suis une chaine", "!*$"));
- printf("8strcspn %lu\n", strcspn("", ""));
- printf("9strcspn %lu\n", strcspn("", NULL));
- fflush(stdout);
- free(ptr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement