小编Som*_*cat的帖子

在 C 中用 LF 替换 CR LF

我必须编写一个功能类似于 dos2unix 的 C 程序。将全部替换CR LF为LF(DOS-Format to Unix-Format)。所以这是我的方法。每次我读一行时,我都会通过lookng for 来搜索数据的结尾\0,然后检查以下是否是\r\n. 如果是,\n只替换。但它似乎不起作用,并且该行CRLF here从未打印过一次。

char data[255]; // save the data from in.txt
char *checker;
pf = fopen("in.txt", "r");
pf2 = fopen("out.txt", "w");
while (feof(pf) == 0)
{
    fgets(data, 255, pf);       // Read input data
    checker = data;
    while (checker != "\0") // Search for a new line
    {
        if (checker == "\r\n") // Check if this is CR LF
        { …
Run Code Online (Sandbox Code Playgroud)

c newline carriage-return

1
推荐指数
1
解决办法
3249
查看次数

标签 统计

c ×1

carriage-return ×1

newline ×1