remove whitespaces tail from string (char*)

随声附和 提交于 2019-12-13 02:56:40

问题


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

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

回答1:


Take a gander at the deblank function. Here's a link: http://www.mathworks.com/help/matlab/ref/deblank.html



来源:https://stackoverflow.com/questions/12582955/remove-whitespaces-tail-from-string-char

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!