commit
This commit is contained in:
29
C_03/git/ex03/ft_strncat.c
Normal file
29
C_03/git/ex03/ft_strncat.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/12 16:43:59 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/12 16:47:35 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
char *ft_strncat(char *dest, char *src, unsigned int nb)
|
||||
{
|
||||
char *s1;
|
||||
char *s2;
|
||||
|
||||
s1 = dest;
|
||||
s2 = src;
|
||||
while (*s1 != '\0')
|
||||
s1++;
|
||||
while (nb > 0 && *s2 != '\0')
|
||||
{
|
||||
*s1++ = *s2++;
|
||||
nb--;
|
||||
}
|
||||
*s1 = '\0';
|
||||
return (dest);
|
||||
}
|
||||
41
C_03/git/ex03/main.c
Normal file
41
C_03/git/ex03/main.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/12 16:21:11 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/12 16:44:38 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *ft_strncat(char *dest, char *src, unsigned int nb);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char src[32];
|
||||
char dest[32];
|
||||
char dest2[32];
|
||||
unsigned int nb;
|
||||
char *r;
|
||||
|
||||
nb = 0;
|
||||
printf("Input String #1 [max 31]: ");
|
||||
scanf("%s", src);
|
||||
printf("Input String #2 [max 31]: ");
|
||||
scanf("%s", dest);
|
||||
printf("Input Number: ");
|
||||
scanf("%u", &nb);
|
||||
strcpy(dest2, dest);
|
||||
r = ft_strncat(dest, src, nb);
|
||||
printf("src=%s dest=%s nb=%d result=%s (ft_strncat)\n", src, dest, nb, r);
|
||||
r = strncat(dest2, src, nb);
|
||||
printf("src=%s dest=%s nb=%d result=%s (strncat)\n", src, dest2, nb, r);
|
||||
return (0);
|
||||
}
|
||||
8
C_03/git/ex03/main.sh
Executable file
8
C_03/git/ex03/main.sh
Executable 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
|
||||
Reference in New Issue
Block a user