Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 829c20fc3f | |||
| 1e619c0e11 | |||
| 47db2563fb | |||
| 28546c7ce1 |
@@ -5,3 +5,4 @@
|
||||
.log
|
||||
|
||||
*.html
|
||||
assets.tar.gz
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
/*
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,6 +22,7 @@ int print_lines(const char *filename){
|
||||
printf("\n");
|
||||
*/
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
*/
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user