在C中如何编写适合OS的行尾字符? [英] In C how to write whichever end of line character is appropriate to the OS?

查看:78
本文介绍了在C中如何编写适合OS的行尾字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Unix具有\ n,Mac是\ r,但现在是\ n,而DOS/Win32是\ r \ n.使用C创建文本文件时,如何确保使用适合操作系统的任何行尾字符?

Unix has \n, Mac was \r but is now \n and DOS/Win32 is \r\n. When creating a text file with C, how to ensure whichever end of line character(s) is appropriate to the OS gets used?

推荐答案

fprintf(your_file, "\n");

如果您以文本模式打开文件,则操作系统上的stdio库会将其转换为适当的EOL.在二进制模式下,不会进行任何转换.

This will be converted to an appropriate EOL by the stdio library on your operating system provided that you opened the file in text mode. In binary mode no conversion takes place.

这篇关于在C中如何编写适合OS的行尾字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆