fopen sometimes not writing all message and saved?

Hi everyone!!!
I have SDP for encrypted and decrypted message but sometimes not save all encrypted message.
for example:
S is encrypted message.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
S=`@ `!@ AA C@@@ACCACACCAEAEEAAEEEIIEAIAAYIYAIIAAAAaaAqaAaaAaA!aA!!AA
fh=fopen('tower.txt','w');
fprintf(fh, '%s' ,S);
fclose(fh);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
but tower.txt file has just
`@
please tell me
why not save all?
and how to solve it?
thank you

 Accepted Answer

fprintf() stops at NUL characters inside strings. That is, it stops at characters with value binary 0. This has to do with the fact that the underlying libraries treat binary 0 as the marker for end of string (this is a design that goes back numerous decades.)
You should not use fprintf() for what you are doing.
fwrite(fh, S);

More Answers (0)

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!