0
0
This commit is contained in:
Guy Baconniere
2021-08-20 10:02:38 +02:00
parent 5aa02c94b5
commit d30270c485
354 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/09 18:19:08 by gbaconni #+# #+# */
/* Updated: 2021/08/12 09:49:18 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strncpy(char *dest, char *src, unsigned int n)
{
unsigned int i;
i = 0;
while (i < n && src[i] != '\0')
{
dest[i] = src[i];
i++;
}
while (i < n)
{
dest[i] = '\0';
i++;
}
return (dest);
}

37
C_02/git/ex01/main.c Normal file
View File

@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/09 18:18:58 by gbaconni #+# #+# */
/* Updated: 2021/08/11 18:07:07 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
char *ft_strncpy(char *dest, char *src, unsigned int n);
int main(void)
{
char src[32];
char dest[64];
unsigned int n;
char *result;
n = 0;
printf("Input String [max 31]: ");
scanf("%s", src);
printf("Input Size: ");
scanf("%d", &n);
result = ft_strncpy(dest, src, n);
printf("src=%s dest=%s n=%d result=%s (ft_strncpy)\n", src, dest, n, result);
result = strncpy(dest, src, n);
printf("src=%s dest=%s n=%d result=%s (strncpy)\n", src, dest, n, result);
return (0);
}

8
C_02/git/ex01/main.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -e
#norminette -R CheckForbiddenSourceHeader ft_*.c
norminette -R CheckForbiddenSourceHeader
gcc -Wall -Wextra -Werror -o a.out *.c
echo $(basename $PWD):
./a.out
rm -f a.out