{"id":22509097,"url":"https://github.com/vinislima/42sp_piscine_c03","last_synced_at":"2025-03-28T00:21:58.171Z","repository":{"id":261882194,"uuid":"885622101","full_name":"vinislima/42sp_piscine_c03","owner":"vinislima","description":"These exercises aim to deepen understanding of string handling and manipulation in C.","archived":false,"fork":false,"pushed_at":"2024-11-23T01:38:27.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T02:18:30.834Z","etag":null,"topics":["42born2code","42network","42saopaulo","string-manipulation"],"latest_commit_sha":null,"homepage":"https://www.linkedin.com/in/viniciusslima/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vinislima.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-09T00:47:52.000Z","updated_at":"2024-11-23T01:38:30.000Z","dependencies_parsed_at":"2024-11-09T01:31:18.673Z","dependency_job_id":"ca57492f-6ace-496e-acc9-fe6497ea92a9","html_url":"https://github.com/vinislima/42sp_piscine_c03","commit_stats":null,"previous_names":["vinislima/42sp_piscine_c03"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinislima%2F42sp_piscine_c03","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinislima%2F42sp_piscine_c03/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinislima%2F42sp_piscine_c03/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinislima%2F42sp_piscine_c03/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vinislima","download_url":"https://codeload.github.com/vinislima/42sp_piscine_c03/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245945011,"owners_count":20698144,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["42born2code","42network","42saopaulo","string-manipulation"],"created_at":"2024-12-07T01:27:27.821Z","updated_at":"2025-03-28T00:21:58.136Z","avatar_url":"https://github.com/vinislima.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [C 03](https://github.com/vinislima/42sp_piscine_c03)\n\nThe functions in Module C 03 focus on replicating standard C library string operations. They include comparing strings (`ft_strcmp`, `ft_strncmp`), concatenating strings (`ft_strcat`, `ft_strncat`), finding substrings (`ft_strstr`), and managing string length during concatenation (`ft_strlcat`). These exercises aim to deepen understanding of string handling and manipulation in C.\n\n- **`ft_strcmp`** - Recreates the behaviour of the `strcmp` function, comparing two strings lexicographically.\n- **`ft_strncmp`** - Recreates the behaviour of the `strncmp` function, comparing up to `n` characters of two strings lexicographically.\n- **`ft_strcat`** - Recreates the behaviour of the `strcat` function, appending the source string (`src`) to the end of the destination string (`dest`).\n- **`ft_strncat`** - Recreates the behaviour of the `strncat` function, appending up to `n` characters of the source string (`src`) to the end of the destination string (`dest`).\n- **`ft_strstr`** - Recreates the behaviour of the `strstr` function, locating the first occurrence of a substring (`to_find`) within a string (`str`).\n- **`ft_strlcat`** - Recreates the behaviour of the `strlcat` function, appending a source string (`src`) to a destination string (`dest`) with size constraints, and returning the total length of the string it tried to create.\n\nThis module in the 42 C Piscine focuses on advanced string manipulation using functions that replicate behaviours from the C standard library. The tasks progress in difficulty, covering comparisons, concatenation, substring searches, and string length management.\n\nStudents must follow strict norms and submit only the required files to pass the automated grading system, Moulinette. Adherence to these guidelines ensures the code compiles and functions correctly under specific compiler flags (`-Wall -Wextra -Werror`).\n\n## Usage\n\nUncomment the main and use the command below.\n\n```c\ncc -Wall -Wextra -Werror {file}\n\n```\n\n---\n\u003cdetails\u003e\n    \u003csummary\u003eExercises:\u003c/summary\u003e\n\n- [ex00:](https://github.com/vinislima/42sp_piscine_c03/blob/main/ex00/ft_strcmp.c)\n    \n    ```c\n    /* ************************************************************************** */\n    /*                                                                            */\n    /*                                                        :::      ::::::::   */\n    /*   ft_strcmp.c                                        :+:      :+:    :+:   */\n    /*                                                    +:+ +:+         +:+     */\n    /*   By: vinda-si \u003cvinda-si@student.42sp.org.br\u003e    +#+  +:+       +#+        */\n    /*                                                +#+#+#+#+#+   +#+           */\n    /*   Created: 2024/08/29 09:34:21 by vinda-si          #+#    #+#             */\n    /*   Updated: 2024/11/22 20:39:09 by vinda-si         ###   ########.fr       */\n    /*                                                                            */\n    /* ************************************************************************** */\n    \n    // Essa função têm como objetivo comparar duas strings\n    // e retornar um valor inteiro que representa a diferença\n    // entre elas, caso não haja diferença, a função retornará 0.\n    int\tft_strcmp(char *s1, char *s2);\n    \n    int\tft_strcmp(char *s1, char *s2)\n    {\n    \t// realizo a declaração de uma variável que será utilizada\n    \t// como um contador\n    \tint\tcount;\n    \t// atribuímos o valor de zero ao contador, para percorrer as strings\n    \tcount = 0;\n    \t// enquanto os elementos das strings forem iguais e diferentes de nulo\n    \t// o laço será executado\n    \twhile ((s1[count] == s2[count])\n    \t\t\u0026\u0026 (s1[count] != '\\0') \u0026\u0026 (s2[count] != '\\0'))\n    \t{\n    \t\t// enquanto a condição for verdadeira, o contador é incrementado\n    \t\tcount++;\n    \t}\n    \t// ao final do laço, é retornado a diferença entre os elementos\n    \treturn (s1[count] - s2[count]);\n    }\n    \n    // main begin here\n    // #include \u003cstdio.h\u003e\n    // #include \u003cstring.h\u003e\n    \n    // int\tmain(void)\n    // {\n    // \t// Test cases\n    // \tchar *test_cases[][2] = {\n    // \t\t{\"hello\", \"hello\"},\n    // \t\t{\"hello\", \"world\"},\n    // \t\t{\"apple\", \"apples\"},\n    // \t\t{\"\", \"\"},\n    // \t\t{\"\", \"non-empty\"},\n    // \t\t{\"non-empty\", \"\"},\n    // \t\t{\"abc\", \"abz\"},\n    // \t\t{\"same\", \"same\"},\n    // \t\t{NULL, NULL} // Marcador para o fim dos testes\n    // \t};\n    \n    // \tint i = 0; // contador para percorrer os testes\n    // \twhile (test_cases[i][0] != NULL \u0026\u0026 test_cases[i][1] != NULL)\n    // \t{\n    // \t\tchar *s1 = test_cases[i][0];\n    // \t\tchar *s2 = test_cases[i][1];\n    \t\t\n    // \t\t// Resultados das funções\n    // \t\tint result_ft = ft_strcmp(s1, s2);\n    // \t\tint result_lib = strcmp(s1, s2);\n    \n    // \t\t// Exibição dos resultados\n    // \t\tprintf(\"Test %d:\\n\", i + 1);\n    // \t\tprintf(\"  Strings: \\\"%s\\\" vs \\\"%s\\\"\\n\", s1, s2);\n    // \t\tprintf(\"  ft_strcmp: %d | strcmp: %d\\n\", result_ft, result_lib);\n    // \t\tprintf(\"  Match: %s\\n\", (result_ft == result_lib) ? \"Yes\" : \"No\");\n    // \t\tprintf(\"\\n\");\n    \n    // \t\ti++;\n    // \t}\n    \n    // \treturn (0);\n    // }\n    ```\n    \n- [ex01:](https://github.com/vinislima/42sp_piscine_c03/blob/main/ex01/ft_strncmp.c)\n    \n    ```c\n    /* ************************************************************************** */\n    /*                                                                            */\n    /*                                                        :::      ::::::::   */\n    /*   ft_strncmp.c                                       :+:      :+:    :+:   */\n    /*                                                    +:+ +:+         +:+     */\n    /*   By: vinda-si \u003cvinda-si@student.42sp.org.br\u003e    +#+  +:+       +#+        */\n    /*                                                +#+#+#+#+#+   +#+           */\n    /*   Created: 2024/08/29 13:54:13 by vinda-si          #+#    #+#             */\n    /*   Updated: 2024/11/22 20:57:26 by vinda-si         ###   ########.fr       */\n    /*                                                                            */\n    /* ************************************************************************** */\n    \n    // A função ft_strncmp compara duas strings até o limite de n caracteres.\n    int\tft_strncmp(char *s1, char *s2, unsigned int n);\n    // A função ft_strlen calcula o tamanho da string.\n    int\tft_strlen(char *str);\n    // Essa função recebe uma string e calcula o tamanho dela.\n    int\tft_strlen(char *str)\n    {\n    \t// declaramos um inteiro que será o contador.\n    \tint\ti;\n    \t// atribuímos o valor 1 para o contador\n    \ti = 1;\n    \t// enquanto o caractere for diferente de '\\0'\n    \t// o laço continuará.\n    \twhile (str[i] != '\\0')\n    \t{\n    \t\t// o contador é incrementado.\n    \t\ti++;\n    \t}\n    \t// ao final, o contador retorna o tamanho da string.\n    \treturn (i);\n    }\n    // A função ft_strncmp compara duas strings até o limite de n caracteres.\n    int\tft_strncmp(char *s1, char *s2, unsigned int n)\n    {\n    \t// declaramos três variáveis.\n    \t// um unsigned int para contar o número de caracteres.\n    \tunsigned int\tcount;\n    \t// dois int para contar o tamanho das strings.\n    \tint\t\t\t\tcount_s1;\n    \tint\t\t\t\tcount_s2;\n    \t// atribuímos o tamanho das strings para as variáveis\n    \t// utilizando a função ft_strlen\n    \tcount_s1 = ft_strlen(s1);\n    \tcount_s2 = ft_strlen(s2);\n    \t// se n for menor ou igual a 0, a função retorna 0\n    \tif (n \u003c= 0)\n    \t\treturn (0);\n    \t// iniciamos o contador com 0\n    \tcount = 0;\n    \t// enquanto a string 1 for igual a string 2 e o contador for menor que n - 1\n    \t// e as strings não forem nulas o laço continuará.\n    \twhile ((s1[count] == s2[count]) \u0026\u0026 (count \u003c n - 1)\n    \t\t\u0026\u0026 (s1[count] \u0026\u0026 s2[count]))\n    \t{\n    \t\t\t// o contador é incrementado\n    \t\t\tcount++;\n    \t}\n    \t// quando o laço terminar, a função retornará a diferença entre os caracteres\n    \treturn (s1[count] - s2[count]);\n    }\n    \n    // begin of main\n    \n    // #include \u003cstdio.h\u003e\n    // #include \u003cstring.h\u003e\n    \n    // // Prototipo da função ft_strncmp\n    // int ft_strncmp(char *s1, char *s2, unsigned int n);\n    \n    // int main(void)\n    // {\n    // \t// Casos de teste para ft_strncmp\n    // \tstruct {\n    // \t\tchar *s1;\n    // \t\tchar *s2;\n    // \t\tunsigned int n;\n    // \t} test_cases[] = {\n    // \t\t{\"hello\", \"hello\", 5},\n    // \t\t{\"hello\", \"world\", 3},\n    // \t\t{\"apple\", \"apples\", 6},\n    // \t\t{\"test\", \"test123\", 4},\n    // \t\t{\"test\", \"test\", 0},\n    // \t\t{\"abcdef\", \"abcdeg\", 5},\n    // \t\t{\"\", \"\", 3},\n    // \t\t{\"\", \"non-empty\", 5},\n    // \t\t{\"non-empty\", \"\", 5},\n    // \t\t{NULL, NULL, 0} // Marcador de fim\n    // \t};\n    \n    // \tint i = 0; // contador para percorrer os testes\n    // \twhile (test_cases[i].s1 != NULL \u0026\u0026 test_cases[i].s2 != NULL)\n    // \t{\n    // \t\tchar *s1 = test_cases[i].s1;\n    // \t\tchar *s2 = test_cases[i].s2;\n    // \t\tunsigned int n = test_cases[i].n;\n    \n    // \t\t// Resultados das funções\n    // \t\tint result_ft = ft_strncmp(s1, s2, n);\n    // \t\tint result_lib = strncmp(s1, s2, n);\n    \n    // \t\t// Exibição dos resultados\n    // \t\tprintf(\"Test %d:\\n\", i + 1);\n    // \t\tprintf(\"  Strings: \\\"%s\\\" vs \\\"%s\\\", n = %u\\n\", s1, s2, n);\n    // \t\tprintf(\"  ft_strncmp: %d | strncmp: %d\\n\", result_ft, result_lib);\n    // \t\tprintf(\"  Match: %s\\n\\n\", (result_ft == result_lib) ? \"Yes\" : \"No\");\n    \n    // \t\ti++;\n    // \t}\n    \n    // \treturn 0;\n    // }\n    ```\n    \n- [ex02:](https://github.com/vinislima/42sp_piscine_c03/blob/main/ex02/ft_strcat.c)\n    \n    ```c\n    /* ************************************************************************** */\n    /*                                                                            */\n    /*                                                        :::      ::::::::   */\n    /*   ft_strcat.c                                        :+:      :+:    :+:   */\n    /*                                                    +:+ +:+         +:+     */\n    /*   By: vinda-si \u003cvinda-si@student.42sp.org.br\u003e    +#+  +:+       +#+        */\n    /*                                                +#+#+#+#+#+   +#+           */\n    /*   Created: 2024/08/29 19:57:27 by vinda-si          #+#    #+#             */\n    /*   Updated: 2024/11/22 21:17:32 by vinda-si         ###   ########.fr       */\n    /*                                                                            */\n    /* ************************************************************************** */\n    \n    // a função ft_strcat concatena duas strings.\n    char\t*ft_strcat(char *dest, char *src);\n    // ela recebe duas strings como parâmetro\n    // uma de destino e outra de origem.\n    char\t*ft_strcat(char *dest, char *src)\n    {\n    \t// declaramos dois inteiros para\n    \t// sabermos para sabermos onde devemos começar\n    \t// a concatenar a string.\n    \tint\tcount_a;\n    \tint\tcount_b;\n    \t// atribuímos 0 para os contadores.\n    \tcount_a = 0;\n    \tcount_b = 0;\n    \t// enquanto o caractere de destino for diferente de '\\0'\n    \t// o laço continuará.\n    \twhile (dest[count_a] != '\\0')\n    \t\t// o contador é incrementado.\n    \t\tcount_a++;\n    \t// quando o primeiro laço terminar, iniciamos outro a\n    \t// partir do caractere nulo de destino.\n    \twhile (src[count_b] != '\\0')\n    \t{\n    \t\t// destino recebe o caractere de origem a partir\n    \t\t// iniciando da ultima posição, recebendo\n    \t\t// a primeira posição da origem.\n    \t\tdest[count_a] = src[count_b];\n    \t\t// seguimos incrementando os contadores.\n    \t\tcount_a++;\n    \t\tcount_b++;\n    \t}\n    \t// ao final, o caractere nulo é adicionado ao destino.\n    \tdest[count_a] = '\\0';\n    \t// e a função retorna o destino.\n    \treturn (dest);\n    }\n    \n    // begin of main\n    \n    // #include \u003cstdio.h\u003e\n    // #include \u003cstring.h\u003e\n    \n    // // Protótipo da função ft_strcat\n    // char *ft_strcat(char *dest, char *src);\n    \n    // int\tmain(void)\n    // {\n    // \t// Buffers para teste\n    // \tchar dest1[50] = \"Hello\";\n    // \tchar dest2[50] = \"Hello\";\n    // \tchar *src = \" World\";\n    \n    // \t// Testando a concatenação\n    // \tprintf(\"Antes da concatenação:\\n\");\n    // \tprintf(\"  dest1 (ft_strcat): \\\"%s\\\"\\n\", dest1);\n    // \tprintf(\"  dest2 (strcat): \\\"%s\\\"\\n\", dest2);\n    // \tprintf(\"  src: \\\"%s\\\"\\n\\n\", src);\n    \n    // \t// Chamadas das funções\n    // \tft_strcat(dest1, src);\n    // \tstrcat(dest2, src);\n    \n    // \t// Resultados após concatenação\n    // \tprintf(\"Depois da concatenação:\\n\");\n    // \tprintf(\"  ft_strcat: \\\"%s\\\"\\n\", dest1);\n    // \tprintf(\"  strcat: \\\"%s\\\"\\n\", dest2);\n    // \tprintf(\"  Match: %s\\n\", (strcmp(dest1, dest2) == 0) ? \"Yes\" : \"No\");\n    \n    // \treturn (0);\n    // }\n    ```\n    \n- [ex03:](https://github.com/vinislima/42sp_piscine_c03/blob/main/ex03/ft_strncat.c)\n    \n    ```c\n    /* ************************************************************************** */\n    /*                                                                            */\n    /*                                                        :::      ::::::::   */\n    /*   ft_strncat.c                                       :+:      :+:    :+:   */\n    /*                                                    +:+ +:+         +:+     */\n    /*   By: vinda-si \u003cvinda-si@student.42sp.org.br\u003e    +#+  +:+       +#+        */\n    /*                                                +#+#+#+#+#+   +#+           */\n    /*   Created: 2024/08/31 15:07:09 by vinda-si          #+#    #+#             */\n    /*   Updated: 2024/11/22 22:03:14 by vinda-si         ###   ########.fr       */\n    /*                                                                            */\n    /* ************************************************************************** */\n    \n    // A função ft_strncat concatena duas strings até o limite de n caracteres.\n    char\t*ft_strncat(char *dest, char *src, unsigned int nb);\n    // ela recebe duas strings como parâmetro e um inteiro, que é o limite de caracteres.\n    char\t*ft_strncat(char *dest, char *src, unsigned int nb)\n    {\n    \t// declaramos dois inteiros que serão os contadores.\n    \tunsigned int\tcount_a;\n    \tunsigned int\tcount_b;\n    \t// atribuímos 0 para os contadores.\n    \tcount_a = 0;\n    \tcount_b = 0;\n    \t// enquanto o caractere de destino for diferente de '\\0'\n    \t// o laço continuará.\n    \twhile (dest[count_a] != '\\0')\n    \t{\n    \t\t// o contador é incrementado.\n    \t\t// enquanto o caractere de destino for\n    \t\t// diferente de nulo.\n    \t\tcount_a++;\n    \t}\n    \t// quando o primeiro laço terminar, iniciamos outro a\n    \t// partir do caractere nulo de destino.\n    \t// enquanto o caractere de origem for diferente de nulo\n    \t// e o contador for menor que o limite de caracteres\n    \t// o laço continuará.\n    \twhile (src[count_b] != '\\0' \u0026\u0026 count_b \u003c nb)\n    \t{\n    \t\t// destino recebe o caractere de origem a partir\n    \t\t// iniciando da ultima posição, recebendo\n    \t\t// a primeira posição da origem.\n    \t\tdest[count_a] = src[count_b];\n    \t\t// seguimos incrementando os contadores.\n    \t\tcount_a++;\n    \t\tcount_b++;\n    \t}\n    \t// ao final, o caractere nulo é adicionado ao\n    \t// final do destino.\n    \tdest[count_a] = '\\0';\n    \t// e a função retorna o destino.\n    \treturn (dest);\n    }\n    \n    // // begin of main\n    \n    // #include \u003cstdio.h\u003e\n    // #include \u003cstring.h\u003e // Para usar a função original strncat\n    \n    // int\tmain(void)\n    // {\n    // \t// Definição de variáveis para teste\n    // \tchar dest1[50] = \"Hello, \";  // Buffer grande o suficiente para concatenar\n    // \tchar src1[] = \"World!\";\n    // \tunsigned int n1 = 3; // Limite de caracteres a serem concatenados\n    \n    // \tchar dest2[50] = \"Hello, \";  // Outra cópia para comparar com strncat\n    // \tchar src2[] = \"World!\";\n    \n    // \t// Teste usando ft_strncat\n    // \tprintf(\"Antes de ft_strncat: dest1 = '%s'\\n\", dest1);\n    // \tft_strncat(dest1, src1, n1);\n    // \tprintf(\"Depois de ft_strncat: dest1 = '%s'\\n\", dest1);\n    \n    // \t// Teste usando a função original strncat\n    // \tprintf(\"\\nAntes de strncat: dest2 = '%s'\\n\", dest2);\n    // \tstrncat(dest2, src2, n1);\n    // \tprintf(\"Depois de strncat: dest2 = '%s'\\n\", dest2);\n    \n    // \t// Comparação dos resultados\n    // \tif (strcmp(dest1, dest2) == 0)\n    // \t\tprintf(\"\\nOs resultados são iguais!\\n\");\n    // \telse\n    // \t\tprintf(\"\\nOs resultados são diferentes!\\n\");\n    \n    // \treturn 0;\n    // }\n    ```\n    \n- [ex04:](https://github.com/vinislima/42sp_piscine_c03/blob/main/ex04/ft_strstr.c)\n    \n    ```c\n    /* ************************************************************************** */\n    /*                                                                            */\n    /*                                                        :::      ::::::::   */\n    /*   ft_strstr.c                                        :+:      :+:    :+:   */\n    /*                                                    +:+ +:+         +:+     */\n    /*   By: vinda-si \u003cvinda-si@student.42sp.org.br\u003e    +#+  +:+       +#+        */\n    /*                                                +#+#+#+#+#+   +#+           */\n    /*   Created: 2024/08/31 15:56:37 by vinda-si          #+#    #+#             */\n    /*   Updated: 2024/11/22 22:30:26 by vinda-si         ###   ########.fr       */\n    /*                                                                            */\n    /* ************************************************************************** */\n    \n    // A função ft_strstr encontra a primeira ocorrência da string to_find na string str.\n    char\t*ft_strstr(char *str, char *to_find);\n    // Ela recebe duas strings como parâmetro, uma de destino e outra de origem.\n    char\t*ft_strstr(char *str, char *to_find)\n    {\n    \t// declaramos dois inteiros que serão os contadores.\n    \tint\tcount_a;\n    \tint\tcount_b;\n    \t// se a string to_find for nula, a função retorna a string str.\n    \tif (to_find[0] == '\\0')\n    \t{\n    \t\t// retorna a string str.\n    \t\treturn (str);\n    \t}\n    \t// caso contrário, iniciamos o contador com 0.\n    \tcount_a = 0;\n    \t// enquanto o caractere de str for diferente de nulo\n    \t// o laço continuará, verificando se a string to_find\n    \t// está contida na string str.\n    \twhile (str[count_a] != '\\0')\n    \t{\n    \t\t// iniciamos o contador b com 0.\n    \t\tcount_b = 0;\n    \t\t// se cairmos nesse laço, significa que o caractere\n    \t\t// foi encontrado a partir da posição count_a e iremos\n    \t\t// comparar se a string to_find está contida na string str\n    \t\t// incrementando o contador b.\n    \t\twhile (str[count_a + count_b] == to_find[count_b])\n    \t\t{\n    \t\t\t// a partir daqui, o contador b é incrementado.\n    \t\t\tcount_b++;\n    \t\t\t// se o contador b for igual a nulo, significa que\n    \t\t\t// a string to_find foi encontrada e a função retorna\n    \t\t\t// a string str a partir da posição count_a.\n    \t\t\tif (to_find[count_b] == '\\0')\n    \t\t\t\treturn (\u0026str[count_a]);\n    \t\t}\n    \t\tcount_a++;\n    \t}\n    \t// se a string to_find não for encontrada, a função retorna nulo.\n    \treturn (0);\n    }\n    \n    // //begin of main\n    // #include \u003cstdio.h\u003e\n    // #include \u003cstring.h\u003e\n    \n    // int\tmain(void)\n    // {\n    // \t// Casos de teste\n    // \tchar str1[] = \"Hello, World!\";\n    // \tchar to_find1[] = \"World\";\n    // \tchar to_find2[] = \"Hello\";\n    // \tchar to_find3[] = \"\";\n    // \tchar to_find4[] = \"XYZ\";\n    // \tchar to_find5[] = \"o, W\";\n    // \tchar to_find6[] = \"Hello, World!\"; // Igual à string inteira\n    \t\t\n    // \t// Array de substrings para teste\n    // \tchar *to_find_tests[] = {to_find1, to_find2, to_find3, to_find4, to_find5, to_find6};\n    // \tint num_tests = sizeof(to_find_tests) / sizeof(to_find_tests[0]);\n    \n    // \tint i = 0; // Contador para o loop\n    // \twhile (i \u003c num_tests) {\n    // \t\tprintf(\"Test %d:\\n\", i + 1);\n    // \t\tprintf(\"  String: \\\"%s\\\"\\n\", str1);\n    // \t\tprintf(\"  Substring: \\\"%s\\\"\\n\", to_find_tests[i]);\n    \t\t\n    // \t\t// Testa a função ft_strstr\n    // \t\tchar *result_ft = ft_strstr(str1, to_find_tests[i]);\n    // \t\tchar *result_orig = strstr(str1, to_find_tests[i]);\n    \n    // \t\t// Exibe os resultados\n    // \t\tprintf(\"  ft_strstr: %s\\n\", result_ft ? result_ft : \"(null)\");\n    // \t\tprintf(\"  strstr:\t%s\\n\", result_orig ? result_orig : \"(null)\");\n    \n    // \t\t// Verifica se os resultados coincidem\n    // \t\tif (result_ft == result_orig || (result_ft \u0026\u0026 result_orig \u0026\u0026 strcmp(result_ft, result_orig) == 0)) {\n    // \t\t\tprintf(\"  Result: OK\\n\");\n    // \t\t} else {\n    // \t\t\tprintf(\"  Result: Mismatch!\\n\");\n    // \t\t}\n    // \t\tprintf(\"\\n\");\n    // \t\ti++;\n    // \t}\n    // \treturn (0);\n    // }\n    \n    ```\n    \u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinislima%2F42sp_piscine_c03","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvinislima%2F42sp_piscine_c03","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinislima%2F42sp_piscine_c03/lists"}