-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ana Laura Da Silva Volkmann
committed
May 26, 2024
1 parent
731a26d
commit 839a374
Showing
4 changed files
with
70 additions
and
63 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,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": [] | ||
} |
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 @@ | ||
{ | ||
"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" | ||
} |
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: ana-lda- <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* 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 <stdio.h> | ||
/* #include <stdio.h> | ||
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); | ||
} */ |
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 |
---|---|---|
|
@@ -6,15 +6,15 @@ | |
/* By: ana-lda- <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* 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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef GET_NEXT_LINE_BONUS_H | ||
# define GET_NEXT_LINE_BONUS_H | ||
|
||
# ifndef BUFFER_SIZE | ||
# define BUFFER_SIZE 32 | ||
# define BUFFER_SIZE 1 | ||
# endif | ||
|
||
# include <unistd.h> | ||
|