When does printf fail to print?

后端 未结 5 1953
梦谈多话
梦谈多话 2020-12-17 10:42

printf function in c doesn\'t always print the output on screen. For example if you forget to put \\n at the end of string you are printfing you sometimes don\'t get the o/p

5条回答
  •  北海茫月
    2020-12-17 11:38

    There is another special case I just encountered:

    My variables are:

    line="-24 hours"
    line2="24 hours"
    

    and try

    printf $line 
    printf $line2
    

    Neither will work. The second one drops the word "hours" and the first one mistakes -24 as a flag.

    Therefore, whenever I use printf I will remove all the dangerous characters if possible, by using

    sed -r "s/[/\ #;&~]/_/g"
    

    I wish printf's codes can be improved by the developer.

    Take care

提交回复
热议问题