From 136d27fdcc5b4f10266b5a1f16e4005815ab20dd Mon Sep 17 00:00:00 2001 From: Rick Date: Mon, 14 Dec 2020 00:52:24 +0100 Subject: [PATCH] Ajout doc et nouvelle fonction pour check si ligne vide --- lib/utils.c | 39 +++++++++++++++++++++++++++++++++++++++ lib/utils.h | 1 + 2 files changed, 40 insertions(+) diff --git a/lib/utils.c b/lib/utils.c index 7fc56eb..784d15d 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -1,8 +1,17 @@ +#include #include #include #include "utils.h" +/** + * sub_digit(): return the longest sub string with digit + * @str: a string with digit + * + * Extract the longest sub string with digit in a big string. + * + * Return: a int which is the digit + */ int sub_digit(char *str) { int ret = 0; @@ -17,6 +26,14 @@ int sub_digit(char *str) return ret; } +/** + * check_ecl(): check only the ecl (jour4) + * @str: the string to test + * + * Just check if ecl is good + * + * Return: 0 if not good, 1 else + */ int check_ecl(char *str) { str = str + 1; @@ -28,3 +45,25 @@ int check_ecl(char *str) return 0; } + +/** + * check_void_line(): check if one line is blank + * @ptr: a pointer to the file + * + * Check if, in one file, we have an empty line between two line with text + * + * Return: 0 if the line isn’t empty, 1 else + */ +int check_void_line(FILE *ptr) +{ + int ret = 0; + char check_line[2]; + check_line[0] = getc(ptr); + check_line[1] = getc(ptr); + if (check_line[0] == '\n' && (check_line[1] == '\n' || check_line[1] == EOF)) + ret = 1; + + fseek(ptr, -1, SEEK_CUR); + + return ret; +} diff --git a/lib/utils.h b/lib/utils.h index 183efc4..09a407a 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -1,2 +1,3 @@ int sub_digit(char *str); int check_ecl(char *str); +int check_void_line(FILE *ptr);