473,379 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

how to use if else loops in structure

#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
1 1246
weaknessforcats
9,208 Expert Mod 8TB
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

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

Similar topics

23
by: Invalid User | last post by:
While trying to print a none empty list, I accidentaly put an "else" statement with a "for" instead of "if". Here is what I had: if ( len(mylist)> 0) : for x,y in mylist: print x,y else:...
18
by: Ed Davis | last post by:
The following is a code fragment from a simple parser. The return is buried inside the switch statement (the actual switch has several more cases). I can't come up with a good alternative I...
11
by: Mannequin* | last post by:
Hi all, I'm working on a quick program to bring the Bible into memory from a text file. Anyway, I have three questions to ask. First, is my implementation of malloc () correct in the program to...
6
by: Scott Brady Drummonds | last post by:
Hi, everyone, I was in a code review a couple of days ago and noticed one of my coworkers never used for() loops. Instead, he would use while() loops such as the following: i = 0; while (i...
17
by: John Salerno | last post by:
I'm reading Text Processing in Python right now and I came across a comment that is helping me to see for loops in a new light. I think because I'm used to the C-style for loop where you create a...
4
by: so.intech | last post by:
for example, ret = 0; for(i=0; i<3; i ++;) { for(j=0; j<4; j++;) { for(k=0; k<3; k++;) { for(m=0; m<4; m++;) {
3
by: monomaniac21 | last post by:
hi all i have a script that retrieves rows from a single table, rows are related to eachother and are retrieved by doing a series of while loops within while loops. bcos each row contains a text...
4
by: Alchemist | last post by:
What is Python's version for the trinary if..then..else operator? I want a one-liner such as a?b:c for the if..then..else control structure if a then b else c Does Python 2.4 support it?
7
by: Ixiaus | last post by:
I have just come across a site that discusses Python's 'for' and 'while' loops as having an (optional) 'else' structure. At first glance I interpreted it as being a bit like the 'default'...
0
by: Derek Martin | last post by:
On Fri, Jul 18, 2008 at 12:21:49PM -0700, mark floyd wrote: One wonders why... :) Even if Python didn't offer a way to write a for loop in a similar fashion (someone else replied about...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.