how to use if else loops in structure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Suresh T R
    New Member
    • Jan 2016
    • 1

    #1

    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",&arm y[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
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    This code:

    Code:
    if (army[i].height < 200)
    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.

    Comment

    Working...