【发布时间】:2015-08-29 22:42:01
【问题描述】:
我正在尝试检查指针是否指向某个字符。
像这样:
#include<stdio.h>
#include<string.h>
#define a 3
int func(char *);
int main()
{
char *s="a";
int type;
type=func(s);
printf("%d",type);
return 0;
}
int func(char *s)
{
int type;
if(*s=="a")
{
type=1;
}
return type;
}
但我经常收到警告:警告:指针和整数之间的比较 if(*s=="a")
可以比较指针和整数吗?
还有其他方法可以解决这个问题吗?
我可以在不打印的情况下找出指向 *s 的字母吗?
【问题讨论】:
-
第 1 步:以可读的方式格式化您的代码。