aboutsummaryrefslogtreecommitdiff
path: root/c10/ex00
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-07-16 12:58:13 +0200
committerCharles <sircharlesaze@gmail.com>2019-07-16 12:58:13 +0200
commit14914f50c3de6c5444e13cf67db064b03c1c90ef (patch)
tree3ecf5a41b4541980ba0287a431681cd5ae25ad84 /c10/ex00
parent217bcb0d4e3ba60604921cb40d5a11a64f93cfc7 (diff)
downloadpiscine-14914f50c3de6c5444e13cf67db064b03c1c90ef.tar.gz
piscine-14914f50c3de6c5444e13cf67db064b03c1c90ef.tar.bz2
piscine-14914f50c3de6c5444e13cf67db064b03c1c90ef.zip
c09 passed, c10 start, exam00 and exam01
Diffstat (limited to 'c10/ex00')
-rw-r--r--c10/ex00/Makefile17
-rw-r--r--c10/ex00/bonjour4
-rw-r--r--c10/ex00/main.c34
3 files changed, 34 insertions, 21 deletions
diff --git a/c10/ex00/Makefile b/c10/ex00/Makefile
index e69de29..6ee330b 100644
--- a/c10/ex00/Makefile
+++ b/c10/ex00/Makefile
@@ -0,0 +1,17 @@
+OUT = ft_display_file
+CC = gcc
+CCFLAGS = -Wall -Wextra -Werror
+
+.PHONY: all
+all: $(OUT)
+
+$(OUT): main.c
+ $(CC) $(CCFLAGS) -o $(OUT) main.c
+
+.PHONY: clean
+clean:
+
+.PHONY: clean
+fclean: clean
+ rm -f $(OUT)
+
diff --git a/c10/ex00/bonjour b/c10/ex00/bonjour
deleted file mode 100644
index 918a5ef..0000000
--- a/c10/ex00/bonjour
+++ /dev/null
@@ -1,4 +0,0 @@
-bonjour
-je
-suis
-charles
diff --git a/c10/ex00/main.c b/c10/ex00/main.c
index 8fee64a..bcf9e68 100644
--- a/c10/ex00/main.c
+++ b/c10/ex00/main.c
@@ -6,7 +6,7 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/11 18:06:43 by cacharle #+# #+# */
-/* Updated: 2019/07/11 18:45:01 by cacharle ### ########.fr */
+/* Updated: 2019/07/15 13:45:33 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,26 +15,31 @@
#define BUFFER_SIZE 1
#include <stdio.h>
-int write_buffer(char *buf)
+void read_write_file(int fildes)
{
int i;
+ int writing;
+ char buf[BUFFER_SIZE];
- i = 0;
- while (buf[i])
+ writing = 1;
+ while (writing)
{
- write(STDOUT_FILENO, &buf[i], 1);
- /*printf("%d %c\n", buf[i], buf[i]);*/
- if (buf[i] == -1)
- return (1);
- i++;
+ if (read(fildes, buf, BUFFER_SIZE) == 0)
+ break;
+ i = 0;
+ while (buf[i])
+ {
+ write(STDOUT_FILENO, &buf[i], 1);
+ if (buf[i] == -1)
+ writing = 0;
+ i++;
+ }
}
- return (0);
}
int main(int argc, char **argv)
{
int fildes;
- char buf[BUFFER_SIZE];
int reading;
if (argc == 1)
@@ -52,12 +57,7 @@ int main(int argc, char **argv)
write(STDERR_FILENO, "Cannot read file.\n", 18);
return (1);
}
- while (1)
- {
- if (read(fildes, buf, BUFFER_SIZE) == 0)
- break;
- write_buffer(buf);
- }
+ read_write_file(fildes);
close(fildes);
return (0);
}