From 839a3744f124d38c16733b012ed96de49c5efc2b Mon Sep 17 00:00:00 2001 From: Ana Laura Da Silva Volkmann Date: Sun, 26 May 2024 18:11:49 +0100 Subject: [PATCH] pronto --- .vscode/launch.json | 7 ++++ .vscode/tasks.json | 28 +++++++++++++ get_next_line_bonus.c | 94 +++++++++++++++---------------------------- get_next_line_bonus.h | 4 +- 4 files changed, 70 insertions(+), 63 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5c7247b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..08d9005 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc build active file", + "command": "/usr/bin/gcc", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/get_next_line_bonus.c b/get_next_line_bonus.c index 07cced1..b162ef8 100644 --- a/get_next_line_bonus.c +++ b/get_next_line_bonus.c @@ -6,7 +6,7 @@ /* By: ana-lda- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/25 19:23:06 by ana-lda- #+# #+# */ -/* Updated: 2024/05/25 22:19:36 by ana-lda- ### ########.fr */ +/* Updated: 2024/05/26 18:09:39 by ana-lda- ### ########.fr */ /* */ /* ************************************************************************** */ @@ -97,7 +97,7 @@ GNL gerencia vários arquivos abertos ao mesmo tempo. o restante do buffer que ainda não foi processado para cada fd.*/ char *get_next_line(int fd) { - static char *laststr[10]; + static char *laststr[1024]; char *line; if (fd < 0 || BUFFER_SIZE <= 0) @@ -107,68 +107,40 @@ char *get_next_line(int fd) return (NULL); line = ft_getline(laststr[fd]); laststr[fd] = ft_new_left_str(laststr[fd]); - free(laststr[fd]); return (line); } -/* #include +/* #include -int main(void) +int main(void) { - int fd; - int fd1; - int fd2; - char *str; - - fd = open("texto.txt", O_RDONLY); - fd1 = open("texto2.txt", O_RDONLY); - fd2 = open("texto3.txt", O_RDONLY); - if (fd == -1) - { - printf("Error\n"); - return (0); - } - str = get_next_line(fd); - printf("line 1 -> %s\n", str); - free(str); - str = get_next_line(fd1); - printf("line 2 -> %s\n", str); - free(str); - str = get_next_line(fd2); - printf("line 3 -> %s\n", str); - free(str); - return (0); -} */ - -/* void handle_file(const char *filename, int line_number) -{ - int fd; - - fd = open(filename, O_RDONLY); - if (fd == -1) - { - printf("Error opening %s\n", filename); - return; - } - - char *str = get_next_line(fd); - if (str) - { - printf("line %d -> %s\n", line_number, str); - free(str); - } - else - { - printf("Error reading line %d from %s\n", line_number, filename); - } - - close(fd); -} - -int main(void) -{ - handle_file("texto.txt", 1); - handle_file("texto2.txt", 1); - handle_file("texto3.txt", 1); - + int fd1; + int fd2; + int fd3; + char *line; + + fd1 = open("texto.txt", O_RDONLY); + fd2 = open("texto2.txt", O_RDONLY); + fd3 = open("texto3.txt", O_RDONLY); + line = get_next_line(fd1); + printf("line 1->%s\n", line); + free (line); + line = get_next_line(fd2); + printf("line 2->%s\n", line); + free (line); + line = get_next_line(fd3); + printf("line 3->%s\n", line); + free (line); + line = get_next_line(fd1); + printf("line 4->%s\n", line); + free (line); + line = get_next_line(fd2); + printf("line 5->%s\n", line); + free (line); + line = get_next_line(fd3); + printf("line 6->%s\n", line); + free (line); + close (fd1); + close (fd2); + close (fd3); return (0); } */ \ No newline at end of file diff --git a/get_next_line_bonus.h b/get_next_line_bonus.h index 5498148..49ac384 100644 --- a/get_next_line_bonus.h +++ b/get_next_line_bonus.h @@ -6,7 +6,7 @@ /* By: ana-lda- +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/25 19:23:22 by ana-lda- #+# #+# */ -/* Updated: 2024/05/25 21:41:21 by ana-lda- ### ########.fr */ +/* Updated: 2024/05/26 17:36:57 by ana-lda- ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ # define GET_NEXT_LINE_BONUS_H # ifndef BUFFER_SIZE -# define BUFFER_SIZE 32 +# define BUFFER_SIZE 1 # endif # include