By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,404 Members | 2,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,404 IT Pros & Developers. It's quick & easy.

how to use if else loops in structure

P: 1
#include<stdio.h>
#include<stdlib.h>
void main()
{
struct army
{
char name[20];
char adress[50];
char age[10];
char contact[20];
char height[10];

};

struct army army[50];
int i,n;
printf("Enter the number of army person \n");
scanf("%d",&n);
printf("ENTER THE ARMY MAN DETAILS \n\n");
for(i=1;i<=n;i++)
{
printf("Enter the name of army person \n");
scanf("%s",army[i].name);
printf("Enter the adress of army person \n");
scanf("%s",army[i].adress);
printf("Enter the age of army person \n");
scanf("%s",army[i].age);
printf("Enter the contact of army person \n");
scanf("%s",army[i].contact);
printf("Enter the height of the army man \n");
scanf("%s",&army[i].height);

}

for(i=1;i<=n;i++)
{
printf("The army man name is %s \n",army[i].name);
printf("The army man adress is %s \n",army[i].adress);
printf("The age of army man is %s \n",army[i].age);
printf("The contact number of army man is %s \n",army[i].contact);
printf("The army man height is %s \n",army[i].height);

if(army[i].height < 200)


printf("He is eligble to join army \n");

else


printf("He is not eligible \n");

}
}
IN THIS I AM GETTING43 19 E:\suresh\army.c [Warning] comparison between pointer and integer
HOW TO OVERCOME FROM THIS PLEASE HELP ME..!!! TO SOLVE THIS
Jan 30 '16 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
This code:

Expand|Select|Wrap|Line Numbers
  1. if (army[i].height < 200)
  2. etc...
height is an array. You will need to specify which element of height you compare to 200.

By definition, the name of an array is the address of element 0. Therefore, height is the address of height[0]. height[0] is a char making height a char*. The compiler sees the compare as a char* to an int (the 200). Hence the warning.
Jan 30 '16 #2

Post your reply

Sign in to post your reply or Sign up for a free account.