I was trying to output a not null terminated char array to a file.
Actual thing is, I am receiving packets and then printing their fields.
Now as these field
A cheap solution would be to have a buffer that has space for an extra null character and just put a null character at the point when you know the actual size and then output the null-terminated buffer as you already do. Fast and reliable.