简体   繁体   English

从字符串(char *)删除空格尾

[英]remove whitespaces tail from string (char*)

hello I've got text file with lines format 你好,我有行格式的文本文件

1|few ewf ew fewfew 

I need to parse it but I don't know how can I drop whitespaces tail from second value I don't know. 我需要解析它,但我不知道如何从我不知道的第二个值中删除空格尾。

Here is my segmentation fault try so far 到目前为止,这是我的segmentation fault

char* token1;
char* token2;
char* search = "|";
char* search2 = "  "; // double space because string can contains single space
while (fgets(line, 150, f)) {
  token1 = strtok(line, search);
  token2 = strtok(search, search2); // <- segfault
  //token2 = strtok(NULL, search); <- contains a lot of spaces in tail

Take a gander at the deblank function. deblank功能。 Here's a link: http://www.mathworks.com/help/matlab/ref/deblank.html 这是链接: http : //www.mathworks.com/help/matlab/ref/deblank.html

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

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