Add all files
This commit is contained in:
57
C_Piscine_C_02/tests_C02/ex01.c
Normal file
57
C_Piscine_C_02/tests_C02/ex01.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ex01.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tkondrac <tkondrac@student.42lausan> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/08 15:03:03 by tkondrac #+# #+# */
|
||||
/* Updated: 2021/08/08 16:59:55 by tkondrac ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "../ex01/ft_strncpy.c"
|
||||
#include "rand_string.c"
|
||||
|
||||
int ft_test(char *src, unsigned int l);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ft_test("0123456789", 15);
|
||||
ft_test("test", 8);
|
||||
ft_test("0123456789" , 3);
|
||||
ft_test("un autre test" , 0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int ft_test(char *src, unsigned int l)
|
||||
{
|
||||
char *dest;
|
||||
char *dest2;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
dest = (char*)malloc(11 * sizeof(char));
|
||||
while(i < 10)
|
||||
{
|
||||
*(dest + i) = '0';
|
||||
i++;
|
||||
}
|
||||
*(dest + i) = '\0';
|
||||
dest2 = ft_strncpy(dest, src, l);
|
||||
printf("-------------\nTest\nsrc string : %s | copy lenght : %u\ndest string : %s | output string : %s\n", src, l, dest, dest2);
|
||||
// Strncpy tests
|
||||
while(i < 10)
|
||||
{
|
||||
*(dest + i) = '0';
|
||||
i++;
|
||||
}
|
||||
*(dest + i) = '\0';
|
||||
dest2 = strncpy(dest, src, l);
|
||||
printf("TEST string : %s | output TEST : %s\n", dest, dest2);
|
||||
free(dest);
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user