c - 如何修复错误“指针和整数之间的比较”?
问题描述
我一直在尝试比较结构变量和字符串变量。但我收到了这个错误。
#include<stdio.h>
#include<string.h>
int main()
{
struct details {
char number[20];
} det[10];
int inp, i=0;
char aad;
int b;
puts("Give The Number To Display The Pass Status");
scanf("%s", &aad);
for(b=0;b<i;b++)
{
if(det[i].number==aad)
{
printf("Hello");
}
}
return 0;
}
请尝试修复我的错误
解决方案
在您查看评论后,这将是答案
#include<stdio.h>
#include<string.h>
#define SIZE 20 // add size for aad
int main()
{
struct details {
char number[20];
} det[10];
int inp, i = 0;
char aad[SIZE]; // must be array (can be with pointer, use malloc)
int b;
puts("Give The Number To Display The Pass Status");
scanf("%s", &aad);
for (b = 0; b < i; b++)
{
if (strcmp(det[b].number, aad) == 0) // strcmp to compare strings
{
printf("Hello");
}
}
return 0;
}
推荐阅读
- python - 使用while循环从函数返回变量
- mysql - The syntax of this MySQL logic?
- laravel-5 - 使用 swagger 在 laravel 中出现错误 419(未知状态)
- python - 使用 pymc3 对 MCMC 进行采样时,如何在可能性上添加 L1 正则化?
- web - 如何在 Weblogic 12.1.1 中导出数据源
- c - 如何使用 ## 运算符连接和评估宏
- php - PHP只更改ini文件中的一个值
- javascript - 分配给这个 javascript 工厂的参数是什么?
- batch-file - 如何将一行代码发送到另一个批处理文件中,该行中有一个特殊字符
- javascript - Identity.IsAuthenticated 在 ASP.Net Web API 中返回 false