i’m using fwrite to write an array of type uint8_t. in the terminal, after running the program, when i use
cat file.txt
everything prints as it should be.
but when i open the file with
vim file.txt
i get a super whack file with a bunch of jibberish, mainly a high repitition of
^@^@^@^@^@^@...
vim also notes [noeol] at the bottom of the open window
context of problem: udp client/server file copy program. i need the original file to diff with my new file; which it does not.
uint8_t buf[...];
recvfrom(...buf...);
fwrite(buf...);
the original file has ~150 characters, the jibberish file has ~ 30k characters.
i would appreciate any kind of answer or direction
-austin
When vim encounter a non-printable character in a file, it use an escape code to represent it. The
^@escape code is used to represent the null character (i.e.'\0'in C). This character being non-printable, the console just discard it when you docat file.txt.So I think that your code is passing an incorrect size to the
fwritecall. Are passing the size of the buffer instead of the size of the received data?Your code should read something like (with proper error checking):