0
0
This commit is contained in:
2021-08-19 08:28:25 +02:00
parent 0f3c227c01
commit 0e8898635b
8 changed files with 118 additions and 6 deletions

View File

@@ -11,7 +11,6 @@
/* ************************************************************************** */
#include <stdlib.h>
#include <stdio.h>
int *ft_range(int min, int max)
{
@@ -20,10 +19,10 @@ int *ft_range(int min, int max)
int i;
if (min < max)
size = max - min;
size = (max - min) + 1;
else
return (NULL);
range = (int *) malloc(size * sizeof(char));
range = (int *) malloc(size * sizeof(int));
i = 0;
while (i < size)
{

View File

@@ -32,10 +32,9 @@ int main(void)
printf("Input Max: ");
scanf("%d", &max);
result = ft_range(min, max);
size = 0;
while (result[size++])
continue ;
printf("min=%d max=%d (ft_range)\nresult:\n", min, max);
size = (max - min) + 1;
printf("size=%d\n", size);
i = 0;
while (i < size)
{

Binary file not shown.

View File

@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/18 18:13:35 by gbaconni #+# #+# */
/* Updated: 2021/08/18 18:32:22 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int ft_ultimate_range(int **range, int min, int max)
{
int *r;
int size;
int i;
(void) range;
if (min < max)
size = (max - min) - 1;
else
{
r = NULL;
range = &r;
return (0);
}
r = (int *) malloc(size * sizeof(int));
i = 0;
while (i < size)
{
r[i] = min + i + 1;
i++;
}
range = &r;
return (size);
}

View File

@@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/18 18:11:09 by gbaconni #+# #+# */
/* Updated: 2021/08/18 18:31:33 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int ft_ultimate_range(int **range, int min, int max);
int main(void)
{
int i;
int min;
int max;
int size;
int *range;
min = 0;
max = 0;
size = 0;
printf("Input Min: ");
scanf("%d", &min);
printf("Input Max: ");
scanf("%d", &max);
size = ft_ultimate_range(&range, min, max);
printf("size=%d min=%d max=%d (ft_ultimate_range)\nrange:\n", size, min, max);
i = 0;
while (i < size)
{
printf("range[%d] = %d\n", i, range[i]);
i++;
}
return (0);
}

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

23
C_Piscine_C_08/Makefile Normal file
View File

@@ -0,0 +1,23 @@
#
# Copyright (c) 2021 Guy Baconniere.
#
## How to use this Makefile
#
# cd git
# mkdir ex00
# cd ex00
# make -f ../../Makefile ex00
#
clone:
@git clone git@vogsphere.42lausanne.ch:vogsphere/intra-uuid-dc28ac79-9ee2-482c-b047-2b9717fad174-3732452 git
cc:
@norminette -R CheckForbiddenSourceHeader
@gcc -Wall -Wextra -Werror -o a.out *.c
@./a.out
@rm -f a.out
all: clone

Binary file not shown.