-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C Piscine C 03 - OK 100% (2019-12-05)
- Loading branch information
Amanda Puchille pinha
committed
Dec 9, 2019
1 parent
c60bc2c
commit 48b6e66
Showing
20 changed files
with
364 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_strcmp.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: apuchill <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/12/02 21:32:49 by apuchill #+# #+# */ | ||
/* Updated: 2019/12/05 00:02:15 by apuchill ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
int ft_strcmp(char *s1, char *s2) | ||
{ | ||
int c; | ||
|
||
c = 0; | ||
while ((s1[c] == s2[c]) && (s1[c] != '\0') && (s2[c] != '\0')) | ||
c++; | ||
return (s1[c] - s2[c]); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* main.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: galves-d <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/11/29 00:02:08 by galves-d #+# #+# */ | ||
/* Updated: 2019/11/29 07:05:23 by galves-d ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
int ft_strcmp(char *s1, char *s2); | ||
|
||
int main() | ||
{ | ||
char s1[] = "Nada a ver"; | ||
char s2[] = "Teste de Comparacao"; | ||
char s3[] = "Teste"; | ||
|
||
printf("s12: %d, s21: %d, s13: %d, s31: %d, s23: %d, s32: %d", ft_strcmp(s1, s2), ft_strcmp(s2, s1), ft_strcmp(s1, s3), ft_strcmp(s3, s1), ft_strcmp(s2, s3), ft_strcmp(s3, s2)); | ||
printf("\n\ns12: %d, s21: %d, s13: %d, s31: %d, s23: %d, s32: %d", strcmp(s1, s2), strcmp(s2, s1), strcmp(s1, s3), strcmp(s3, s1), strcmp(s2, s3), strcmp(s3, s2)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_strncmp.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: apuchill <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/12/02 22:59:36 by apuchill #+# #+# */ | ||
/* Updated: 2019/12/05 00:05:18 by apuchill ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
int ft_strncmp(char *s1, char *s2, unsigned int n) | ||
{ | ||
unsigned int c; | ||
int diff; | ||
|
||
c = 0; | ||
diff = 0; | ||
while ((c < n) && !diff && (s1[c] != '\0') && (s2[c] != '\0')) | ||
{ | ||
diff = (unsigned char)s1[c] - (unsigned char)s2[c]; | ||
c++; | ||
} | ||
if (c < n && !diff && (s1[c] == '\0' || s2[c] == '\0')) | ||
diff = (unsigned char)s1[c] - (unsigned char)s2[c]; | ||
return (diff); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* main.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: galves-d <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/11/29 00:02:08 by galves-d #+# #+# */ | ||
/* Updated: 2019/11/29 07:06:27 by galves-d ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
int ft_strncmp(char *s1, char *s2, unsigned int n); | ||
|
||
int main() | ||
{ | ||
char s1[] = "Nada a ver"; | ||
char s2[] = "Teste de Comparacao"; | ||
char s3[] = "Teste"; | ||
|
||
printf("s12: %d, s21: %d, s13: %d, s31: %d, s23: %d, s32: %d", ft_strncmp(s1, s2, 5), ft_strncmp(s2, s1, 5), ft_strncmp(s1, s3, 5), ft_strncmp(s3, s1, 5), ft_strncmp(s2, s3, 5), ft_strncmp(s3, s2, 5)); | ||
printf("\n\ns12: %d, s21: %d, s13: %d, s31: %d, s23: %d, s32: %d", strncmp(s1, s2, 5), strncmp(s2, s1, 5), strncmp(s1, s3, 5), strncmp(s3, s1, 5), strncmp(s2, s3, 5), strncmp(s3, s2, 5)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_strcat.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: apuchill <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/12/03 10:21:00 by apuchill #+# #+# */ | ||
/* Updated: 2019/12/04 13:52:33 by apuchill ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
int ft_strlen(char *str) | ||
{ | ||
int counter; | ||
|
||
counter = 0; | ||
while (*str != '\0') | ||
{ | ||
counter++; | ||
str++; | ||
} | ||
return (counter); | ||
} | ||
|
||
char *ft_strcat(char *dest, char *src) | ||
{ | ||
int c; | ||
|
||
c = ft_strlen(dest); | ||
while (*src != '\0') | ||
{ | ||
dest[c] = *src; | ||
c++; | ||
src++; | ||
} | ||
dest[c] = '\0'; | ||
return (dest); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <stdio.h> | ||
|
||
char *ft_strcat(char *dest, char *src); | ||
|
||
int main(void) | ||
{ | ||
char dest[20] = "Hello"; | ||
char src[] = ", world!"; | ||
|
||
printf("-----\ndest = %s\nsrc = %s\n", dest, src); | ||
ft_strcat(dest, src); | ||
printf("result = %s\n-----\n", dest); | ||
|
||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_strncat.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: apuchill <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/12/04 14:01:10 by apuchill #+# #+# */ | ||
/* Updated: 2019/12/05 13:11:00 by apuchill ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
char *ft_strncat(char *dest, char *src, unsigned int nb) | ||
{ | ||
unsigned int c; | ||
unsigned int d; | ||
|
||
c = 0; | ||
d = 0; | ||
while (dest[c] != '\0') | ||
c++; | ||
while (src[d] != '\0' && d < nb) | ||
{ | ||
dest[c + d] = src[d]; | ||
d++; | ||
} | ||
dest[c + d] = '\0'; | ||
return (dest); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <stdio.h> | ||
|
||
char *ft_strncat(char *dest, char *src, unsigned int nb); | ||
|
||
int main(void) | ||
{ | ||
char dest[20] = "123"; | ||
char src[] = "4567890"; | ||
unsigned int nb = 8; | ||
|
||
printf("-----\ndest = %s\nsrc = %s\nnb = %d\n", dest, src, nb); | ||
ft_strncat(dest, src, nb); | ||
printf("result = %s\n-----\n", dest); | ||
|
||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
char *ft_strncat(char *dest, char *src, unsigned int nb) | ||
{ | ||
unsigned int c; | ||
unsigned int d; | ||
|
||
c = 0; | ||
d = 0; | ||
while (dest[c] != '\0') | ||
c++; | ||
while (src[d] != '\0' && d < nb) | ||
{ | ||
dest[c + d] = src[d]; | ||
d++; | ||
} | ||
dest[d + c] = '\0'; | ||
return (dest); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_strstr.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: apuchill <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/12/04 14:36:51 by apuchill #+# #+# */ | ||
/* Updated: 2019/12/04 21:38:22 by apuchill ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
char *ft_strstr(char *str, char *to_find) | ||
{ | ||
int i; | ||
int j; | ||
|
||
i = 0; | ||
if (to_find[0] == '\0') | ||
return (str); | ||
while (str[i] != '\0') | ||
{ | ||
j = 0; | ||
while (str[i + j] == to_find[j] && str[i + j] != '\0') | ||
{ | ||
if (to_find[j + 1] == '\0') | ||
return (&str[i]); | ||
j++; | ||
} | ||
i++; | ||
} | ||
return (0); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <stdio.h> | ||
|
||
char *ft_strstr(char *str, char *to_find); | ||
|
||
int main(void) | ||
{ | ||
char str[] = "012340123456789"; | ||
char to_find[] = "456"; | ||
|
||
printf("-----\nstr = %s\nto_find = %s\n", str, to_find); | ||
printf("%s\n", ft_strstr(str, to_find)); | ||
|
||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* ft_strlcat.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: apuchill <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/12/04 21:44:39 by apuchill #+# #+# */ | ||
/* Updated: 2019/12/05 00:03:33 by apuchill ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
unsigned int ft_strlen(char *str) | ||
{ | ||
unsigned int counter; | ||
|
||
counter = 0; | ||
while (*str != '\0') | ||
{ | ||
counter++; | ||
str++; | ||
} | ||
return (counter); | ||
} | ||
|
||
unsigned int ft_strlcat(char *dest, char *src, unsigned int size) | ||
{ | ||
unsigned int c; | ||
unsigned int d; | ||
|
||
if (size <= ft_strlen(dest)) | ||
return (size + ft_strlen(src)); | ||
c = ft_strlen(dest); | ||
d = 0; | ||
while (src[d] != '\0' && c + 1 < size) | ||
{ | ||
dest[c] = src[d]; | ||
c++; | ||
d++; | ||
} | ||
dest[c] = '\0'; | ||
return (ft_strlen(dest) + ft_strlen(&src[d])); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <stdio.h> | ||
|
||
unsigned int ft_strlcat(char *dest, char *src, unsigned int size); | ||
|
||
int main(void) | ||
{ | ||
char dest[20] = "123"; | ||
char src[] = "4567890"; | ||
unsigned int size = 6; | ||
unsigned int result; | ||
|
||
printf("-----\ndest = %s\nsrc = %s\nnb = %d\n\n", dest, src, size); | ||
result = ft_strlcat(dest, src, size); | ||
printf("dest (cat) = %s\nresult = %d\n-----\n", dest, result); | ||
|
||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* main.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: galves-d <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2019/11/29 05:09:22 by galves-d #+# #+# */ | ||
/* Updated: 2019/12/03 03:45:50 by galves-d ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
unsigned int ft_strlcat(char *dest, char *src, unsigned int size); | ||
|
||
int main() | ||
{ | ||
char str0[50]; | ||
char str1[50]; | ||
char str2[] = "Concatenando 1"; | ||
unsigned int tamanho1; | ||
unsigned int tamanho2; | ||
|
||
str0[0] = 'O'; | ||
str0[1] = 'l'; | ||
str0[2] = 'a'; | ||
str0[3] = '\0'; | ||
|
||
str1[0] = 'O'; | ||
str1[1] = 'l'; | ||
str1[2] = 'a'; | ||
str1[3] = '\0'; | ||
|
||
tamanho1 = ft_strlcat(str0, str2, 0); | ||
tamanho2 = strlcat(str1, str2, 0); | ||
printf("String final: %s, Tamanho: %d", str0, tamanho1); | ||
printf("\nString final: %s, Tamanho: %d", str1, tamanho2); | ||
} |