gpt4 book ai didi

c - 在 C 中如何在字符串中找到 '\' 字符?

转载 作者:太空狗 更新时间:2023-10-29 15:19:51 25 4
gpt4 key购买 nike

假设我有一个用户输入的字符串asdfgh\hj,我想找出\字符在字符串中的索引。我如何在 C 中做到这一点?

我试过 strchr() 函数作为 strchr("asdfgh\hj",'\') 但编译器抛出错误。

然后我使用了 == 运算符,但同样的问题 — 编译器再次抛出错误。

最佳答案

I tried strchr() function as strchr("asdfgh\hj",'\') but compiler throws an error

这是正确的功能!出现错误的原因是 \ 是一个特殊的“转义”字符。它用于定义“特殊”不可打印字符,例如换行符\n。这就是反斜杠本身 \ 需要转义的原因,如下所示:

strchr("asdfgh\\hj",'\\')

关于c - 在 C 中如何在字符串中找到 '\' 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21612289/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com