c_piscine__offshore_mains/c02/ex01.c

62 lines
2.2 KiB
C
Raw Normal View History

2023-11-28 15:40:55 +00:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ex01.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: achubuko <achubuko@student.42yerevan.am> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/27 21:57:45 by achubuko #+# #+# */
/* Updated: 2023/11/27 21:59:11 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
2023-11-23 19:06:22 +00:00
#include "tests.h"
2023-11-28 15:40:55 +00:00
char *ft_strncpy(char*, char*, size_t);
2023-11-23 19:06:22 +00:00
int main(void)
{
2023-11-28 15:40:55 +00:00
char s1[100] = TEST_SOURCE;
char d1[100] = TEST_DESTINATION;
char *r1;
char s2[100] = TEST_SOURCE;
char d2[100] = TEST_DESTINATION;
char *r2;
char s3[100] = TEST_SOURCE;
char d3[100] = TEST_DESTINATION;
char *r3;
char s4[100] = TEST_SOURCE;
char d4[100] = TEST_DESTINATION;
char *r4;
2023-11-23 19:06:22 +00:00
printf("initial strings:\n");
dump(s1, TEST_SOURCE_LENGHT);
dump(d1, TEST_DESTINATION_LENGHT);
2023-11-28 15:40:55 +00:00
r1 = strncpy(d1 , s1, 4);
2023-11-23 19:06:22 +00:00
printf("strncpy(d, s, 4):\n");
dump(s1, TEST_SOURCE_LENGHT);
dump(d1, TEST_DESTINATION_LENGHT);
r2 = ft_strncpy(d2, s2, 4);
printf("ft_strncpy(d, s, 4:\n");
dump(s2, TEST_SOURCE_LENGHT);
dump(d2, TEST_DESTINATION_LENGHT);
printf("buffers comparison: s:%i d:%i\n", bufcmp(s1, s2, TEST_SOURCE_LENGHT), bufcmp(d1, d2, TEST_DESTINATION_LENGHT));
2023-11-28 15:40:55 +00:00
r3 = strncpy(d3 , s3, 20);
2023-11-23 19:06:22 +00:00
printf("strncpy(d, s, 20):\n");
dump(s3, TEST_SOURCE_LENGHT);
dump(d3, TEST_DESTINATION_LENGHT);
r4 = ft_strncpy(d4, s4, 20);
printf("ft_strncpy(d, s, 20):\n");
dump(s4, TEST_SOURCE_LENGHT);
dump(d4, TEST_DESTINATION_LENGHT);
printf("buffers comparison: s:%i d:%i\n", bufcmp(s3, s4, TEST_SOURCE_LENGHT), bufcmp(d3, d4, TEST_DESTINATION_LENGHT));
printf("return values comparison: %li %li %li %li\n", d1 - r1, d2 -r2, d3 - r3, d4 - r4);
}
void setUp(void)
{
}
void tearDown(void)
{
}