My program reads all files in directory "./srcs/" and makes an array of name of the files found.
Then I use the array in main with switch to make a test for each function.
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <stdlib.h>
void *ft_memset(void *dest, int c, size_t nofb);
char **show_dir_content(char * path)
{
DIR *dir;
struct dirent *ent;
struct dirent *entry;
char **array;
int i;
int len;
i = 0;
len = 0;
dir = opendir(path);
if(!dir)
{
perror("diropen");
return(0);
}
while((ent = readdir(dir)) != NULL)
{
if ((ent-> d_name[0]) != '.')
{
len++;
}
}
closedir(dir);
dir = opendir(path);
array = (char**)malloc(sizeof(*array) * len);
while ((entry = readdir(dir)) != NULL)
{
if ((entry-> d_name[0]) != '.')
{
array[i] = entry-> d_name;
i++;
}
}
closedir(dir);
return (array);
}
Here an function which read files from directory and put them in array. Idea is by using switch and while iterate all names of function and execute test. Special test for each.
For that I'm using next menu:
int main(int argc, char **argv)
{
char c[6] = "123fg";
char d[6] = "123fg";
char **ptr;
int hack;
ptr = show_dir_content("./srcs/");
while(*ptr)
{
if(strcmp(*ptr, "ft_memset.c") == 0)
{
hack = 1;
}
switch (hack){
case 1:
ft_memset(c, 'A', 3);
memset(d, 'A', 4);
if(strcmp(c, d) == 0)
{
printf("%s", "OK");
}
else
{
printf("%s", "KO");
}
break;
}
ptr++;
}
free(ptr);
return(0);
}
As test I'm using memset lib function vs ft_memset function created by myself. It has next code:
#include <string.h>
void *ft_memset(void *dest, int c, size_t nofb)
{
unsigned char* p = dest;
while (nofb--)
*p++ = (unsigned char)c;
return (dest);
}