我想知道如何使用 strstrip 内核函数将“hello world”这样的字符串解析为“helloworld”。我正在开发一个 Linux 内核字符设备,这个函数导致我出现内核 panic (或内核 Opss)。
我使用这个函数的方式如下:
char result[100];
strcpy(result, "hello world");
strstrip(result);
strstrip(&result); //Also tried this
strstrip("100+200"); //Also tried this
一旦执行 strstrip 行就会导致内核错误。调用此函数的正确方法是什么?
最佳答案
实际上 strstrip 有助于去除前面的空白。它不会删除字符串中的所有空格。 请看下面的例子。
char result[100];
strcpy(result, " hello world from stack exchange");
printk("\n before: %s",result);
strcpy(result, strstrip((char*)result));
printk("\n after: %s",result);
希望对您有所帮助。
关于linux - 如何使用 strstrip 分两部分解析字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19045211/