string - Pointer and integer comparison warning C -


with –l largest , –s smallest number, if user enters invalid option, program should display error message. have code functioning.

the current error comparison of pointer , integer within first , second if() statements.

#include <stdio.h> #include <stdlib.h> #include <string.h>  int main(int argc, char *numbers[]) {         //variables needed         int i,temp,max,min;          //find largest (-1)         if (!(strcmp(numbers[1],"-1")))         {             max = atoi(numbers[2]);             (i=2;i<argc;i++)             {                     if(numbers[i] >= 'a' && numbers[i] <= 'z')                     {                             printf("bad input");                     }                     else if(numbers[i] >= 'a' && numbers[i] <= 'z')                     {                             printf("bad input");                     }                     else                     {                             temp = atoi(numbers[i]);                             if (max<temp)                             {                                     max = temp;                             }                     }             }             //output after loop             printf("\nthe largest number %d\n",max);      }     else if (!(strcmp(numbers[1],"-s")))     {             min = atoi(numbers[2]);             (i=2;i<argc;i++)             {                     temp = atoi(numbers[i]);                     if (min>temp)                     {                             min = temp;                     }             }             printf("\nthe smallest number %d\n",min);     }     else     {       }     return 0; } 

char *numbers[]

your numbers array of pointer char (note [] has higher precedence * - , that's why it's array pointer), comparision if(numbers[i] >= 'a' && numbers[i] <= 'z') doesn't make sense.

what need if(numbers[i][0] >= 'a' && numbers[i][0] <= 'z'). following condition, should if(numbers[i][0] >= 'a' && numbers[i][0] <= 'z'). because char *numbers[] array of pointer char, numbers[i] pointer char, , first character can accessed via numbers[i][0]


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -