ras le bol

This commit is contained in:
2026-02-23 01:15:30 +01:00
parent fba51abae3
commit 28dee070b3
38 changed files with 442 additions and 321 deletions
@@ -1,3 +1,4 @@
#include <stdio.h>
enum data_type {
STRING,
INTEGER,
@@ -6,6 +7,63 @@ enum data_type {
int write_format(void *data, enum data_type type, char *filename)
{
// FIXME: Implement this function
FILE *file = fopen(filename, "a");
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;
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;
}
*/