From 28546c7ce168226aab54442928f5eef750e614bb Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 23 Feb 2026 09:46:54 +0100 Subject: [PATCH] go --- .../fundamentals/basic_read/basic_read.c | 4 +- .../fundamentals/basic_write/basic_write.c | 6 +- .../hidden_message/hidden_message.c | 8 ++- .../fundamentals/print_lines/print_lines.c | 9 ++- .../fundamentals/write_format/write_format.c | 60 ++----------------- 5 files changed, 22 insertions(+), 65 deletions(-) diff --git a/Who_robbed_Thibouvre/fundamentals/basic_read/basic_read.c b/Who_robbed_Thibouvre/fundamentals/basic_read/basic_read.c index df16849..cd8fc3f 100644 --- a/Who_robbed_Thibouvre/fundamentals/basic_read/basic_read.c +++ b/Who_robbed_Thibouvre/fundamentals/basic_read/basic_read.c @@ -25,8 +25,8 @@ int read_n_bytes(const char *filename, size_t n){ } fread(cara, sizeof(char), n, file); - //cara[n+1] = '\0'; - //printf("%s\n", cara); + cara[n+1] = '\0'; + printf("%s\n", cara); free(cara); fclose(file); return 0; diff --git a/Who_robbed_Thibouvre/fundamentals/basic_write/basic_write.c b/Who_robbed_Thibouvre/fundamentals/basic_write/basic_write.c index 3894c6a..f630a99 100644 --- a/Who_robbed_Thibouvre/fundamentals/basic_write/basic_write.c +++ b/Who_robbed_Thibouvre/fundamentals/basic_write/basic_write.c @@ -11,7 +11,7 @@ int write_one_by_one(char *filename, const char *text){ index ++; } //fputc(*text, file); - fputc('\0', file); + //fputc('\0', file); fclose(file); return 0; } @@ -21,7 +21,9 @@ int write_all_in_one(char *filename, const char *text){ FILE *file = fopen(filename, "w"); if(!file)return 1; - fprintf(file, text); + fprintf(file, "%s\n", text); + + fclose(file); return 0; } /* diff --git a/Who_robbed_Thibouvre/fundamentals/hidden_message/hidden_message.c b/Who_robbed_Thibouvre/fundamentals/hidden_message/hidden_message.c index 1ea501d..7f50719 100644 --- a/Who_robbed_Thibouvre/fundamentals/hidden_message/hidden_message.c +++ b/Who_robbed_Thibouvre/fundamentals/hidden_message/hidden_message.c @@ -6,15 +6,17 @@ int hidden_message(const char *filename, const char delim){ int c = fgetc(file); - printf("%c", c); + if (c != EOF) putchar(c); //char *cara = c; while(c != EOF){ c = fgetc(file); + if( c == delim){ - c = fgetc(file); - printf("%c", c); + while(c == delim) c = fgetc(file); + + if (c != EOF && c != delim)putchar(c); } } fclose(file); diff --git a/Who_robbed_Thibouvre/fundamentals/print_lines/print_lines.c b/Who_robbed_Thibouvre/fundamentals/print_lines/print_lines.c index 5d7962c..68aab93 100644 --- a/Who_robbed_Thibouvre/fundamentals/print_lines/print_lines.c +++ b/Who_robbed_Thibouvre/fundamentals/print_lines/print_lines.c @@ -7,9 +7,13 @@ int print_lines(const char *filename){ // int c = fgetc(file); int c = fgetc(file); + printf("> "); while(c != EOF){ + //if (c == '\n') printf("\n> "); printf("%c", c); + if(c == '\n') printf("> "); c = fgetc(file); + /* while(c != '\0'){ c = fgetc(file); @@ -18,11 +22,12 @@ int print_lines(const char *filename){ printf("\n"); */ } + printf("\n"); return 0; } -/* + int main() { print_lines("example.txt"); @@ -37,4 +42,4 @@ int main() return 0; } -*/ + diff --git a/Who_robbed_Thibouvre/fundamentals/write_format/write_format.c b/Who_robbed_Thibouvre/fundamentals/write_format/write_format.c index 638000b..c651e8a 100644 --- a/Who_robbed_Thibouvre/fundamentals/write_format/write_format.c +++ b/Who_robbed_Thibouvre/fundamentals/write_format/write_format.c @@ -7,63 +7,11 @@ enum data_type { int write_format(void *data, enum data_type type, char *filename) { - FILE *file = fopen(filename, "a"); + FILE *file = fopen(filename, "w"); if(!file) return 1; - printf("%i\n", type); - - if(type == STRING){ - char *var = data; - fprintf(file, "String: %s\n", var); - } - else if (type == INTEGER){ - int *var = data; - //printf("%c", *var % 10 + 48); - /*fprintf(file, "Integer: "); - while(*var > 10){ - char tmp = *var % 10 + 48; - fprintf(file, "%c", tmp); - *var = *var / 10; - } - fprintf(file, "\n");*/ - - fprintf(file,"Integer: %d\n", *var); - } - else if (type == POINTER){ - char *var = data; - fprintf(file, "Pointer: %p\n", var); - } - else return 1; - + fprintf(file, "test"); + // FIXME: Implement this function + fclose(file); return 0; } -/* -int main() -{ - char *str = "Write me!"; - int integer = 42; - int *ptr = &integer; - - //As you can see, we pass an integer pointer to the function. - //This is because genericity only applies to pointers, so you cannot directly pass an integer as a parameter. - //It also means that you will have to dereference it in order to retrieve its value. - - - write_format(str, STRING, "output.txt"); - write_format(ptr, INTEGER, "output.txt"); - write_format(ptr, POINTER, "output.txt"); - // * output.txt should contain: - //String: Write me! - //Integer: 42 - //Pointer: 0x424242424242 // Unfortunately, it may not be the result you will get, but something similar - - - // FLAG - //Complete the function in order to print the password into output.txt. - // - size_t password[2] = { 7940247895376159821, 0 }; - write_format(password, STRING, "output.txt"); - - return 0; -} -*/