My problem is when I try to print text with a "\n", this special characters are invisible for printf and puts after echoing it to file, and reading it again.
#include <stdio.h>
#include <string.h>
int main()
{
FILE *f;
char *s = (char*) malloc (2919);
strcpy(s, "printf 'H4sIAIM4aFYCAwtJLS6JyQsBklwAMrDLnwsAAAA=' | base64 -d | gunzip > r"); //Test\nTest after decoding
system(s);
f = fopen("r", "r");
fseek(f, SEEK_SET, 0);
fread(s, 2919, 1, f);
printf("%s", s); //puts(s); gives the same result
fclose(f);
system("rm r");
free(s);
return 0;
}
Output should look like:
Test
Test
and it looks like Test\nTest
. What am I doing wrong?
Learning purpose, so please be nice.
The text you've encoded looks like this:
Test\nTest
This is a 10 character string with "\" for the fifth character and "n" for the sixth. This is different from this:
char str[]="Test\nTest";
Which is a 9 character string with a newline for the fifth character.
If you want to print a newline, your encoded string needs to contain it. Either that, or you have to parse the resulting string and perform the newline substitution manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With