且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在.txt文件中的每一行的末尾删除^ M。

更新时间:2023-12-03 21:22:28

您只需通过删除AY \\ r \\ n缩短字符串结尾,例如:人物变化:

You can just shorten the string by deleting ay \r or \n characters at the end, e.g. change:

  ...
  strcpy(linec, line);
  ...

  int len;
  ...
  strcpy(linec, line);
  len = strlen(linec);                   // get length of string
  while (len > 0)                        // while string not empty
  {                                      // if last char is \r or \n
      if (linec[len - 1] == '\r' || linec[len - 1] == '\n')
      {
          linec[len - 1] = '\0';         // delete it
          len--;
      }
      else                               // otherwise we found the last "real" character
          break;
  }
  ...

请注意,当你打印字符串,您将需要添加一个换行符,例如用

Note that when you print the string you will need to add a line feed, e.g. use

fprintf(write, "%s\n", linec);