[英]C | Compare char * with char
I have this code: 我有以下代码:
const char *linesep = "\n";
char buffer[10];
buffer[0] = 'L';
How can I check linesep and buffer[0] are the same? 如何检查lineep和buffer [0]是否相同? Like using strcmp. 就像使用strcmp一样。 Thanks in Advance! 提前致谢!
If you only want to compare a char
to a char
you could simply do this: 如果只想将一个char
与一个char
进行比较,则只需执行以下操作:
#include <stdio.h>
int main(void)
{
const char *linesep = "\n";
char buffer[10];
buffer[0] = 'L';
printf("%s", linesep[0] == buffer[0] ? "same" : "not same");
return 0;
}
Demo: https://ideone.com/kUqkRC 演示: https : //ideone.com/kUqkRC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.