简体   繁体   English

从C中的文本文件中删除控件M

[英]Remove control M from a text file in C

ist is possible? 可能吗? What would be the easiest way? 最简单的方法是什么? I tried to compare in the input string character to character so 我试图比较输入字符串中的字符

if(char([i]=="^M") char[i]="" if(char([i] ==“ ^ M”)char [i] =“”

but it does not work. 但它不起作用。

By the way, if I were able to check it, what is the wistes substitution? 顺便说一句,如果我能够检查一下,wistes的替代品是什么? to "" ? 至 ”” ?

Thanks 谢谢

A control-M isn't stored as a multiple key sequence in a text file. 控件M不会作为多键序列存储在文本文件中。 It's generally stored as the ascii value 13, or 0x0d in hexadecimal. 通常以ascii值13或0x0d(十六进制)形式存储。

So, your statement would be: 因此,您的陈述将是:

if (char[i] == 0x0d) 如果(char [i] == 0x0d)

or 要么

if (char[i] == '\\x0d') 如果(char [i] =='\\ x0d')

If you have a mutable array of char then if you need to remove a given character you'll need to move all the characters after the removed character up one place, not just assign a 'blank' to the given character. 如果您有一个可变的char数组,那么如果您需要删除一个给定的字符,则需要将删除的字符之后的所有字符上移一个位置,而不仅仅是给该给定的字符分配一个“空白”。

It's probably easiest to do this with pointers. 使用指针执行此操作可能最简单。

Eg (in place transformation): 例如(就地转换):

extern char *in;
char *out = in;

while (*in)
{
    if (*in != '\r')
        *out++ = *in;

    in++;
}

*out = '\0';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM