go
This commit is contained in:
@@ -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;
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user