linux - 如何使用 strstrip 分两部分解析字符串

标签 linux ubuntu linux-kernel

我想知道如何使用 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/

相关文章:

c - 汇编程序员在 Linux/x86-64 系统调用中的结构布局?

c - Linux 上的原始 IPv6 数据包处理

linux - 在CentOS 6.0中安装lighttpd

linux - Ubuntu linux Server 12.04.5 LTS 无法安装 apt-show-versions

java - Tomcat8 显示 "web page is not available"

python - 我可以使用 uWSGI Emperor 来管理后台进程吗?

linux - 删除多个 csv 文件的第一行或行(标题)和第一列

ubuntu - Ubuntu 中的三个 linux-image 变体有什么区别?

ajax - XML::Simple 在属性文本中保留实体

c - 在不分配给变量的情况下调用内核内部的非空函数是否安全