Search in shivacherukuri.tech@blogger.com

Wednesday, July 28, 2010

Checking weather given value is under integer range or not

#include<stdio.h>

 

int main(int argc, char *argv[]) {

 

 int i=0;

 int id = 0;

 char temp_name[31];

 char *ch=argv[1];

 char *temp_ch=argv[1];

 

   printf("input is ch:%s..argv[1]:%s\n",ch,argv[1]);

   while (*temp_ch != NULL) {

     id = (id * 10) + (*temp_ch- '0');

     printf(" temp_ch: %c and id:%d \n",*temp_ch,id);

     temp_ch++;

   }

   sprintf(temp_name,"%d",id);

   printf("temp_name : %s\n",temp_name);

   if( (id < 0) || (strcmp(temp_name,ch) != 0)){

      printf("Value enterd is out of integer range \n");

      return 0;

   }

 

   //i = atoi(argv[1]);

 

   //printf("i=%d and passed arg is:%s \n",i,argv[1]);

 

 return 0;

 

}

No comments:

Post a Comment