# 1 "stdio.h"

extern char* gets();

extern short printf();
extern short scanf();

extern short fflush();

extern short getchar();
extern short putc();

struct _FILE {
   short fd;
   short track;
   short head;
   short sector;
};

typedef struct _FILE FILE;

extern FILE * fopen();
extern short fprintf();
extern short fgetchar();
extern short fscanf();
extern short fgets();
extern short fseek();
extern short fread();
extern short fwrite();
extern void fclose();































# 3 "atoi.c"

extern short strlen2();
extern short atoi2();

short
strlen2(ptr)
char * ptr;
{
   short n;
   n = 0;
   while(*ptr) {
     n++;
     ptr++;
   }
   return n;
}

short
atoi2(str)
char * str ;
{
   short ret;
   short i;
   short n;
   short off;
   short num[6];

   num[4] = 10000;
   num[3] = 1000;
   num[2] = 100;
   num[1] = 10;
   num[0] = 1;

   ret = 0;
   n = strlen2(str);

printf("n == %d\r\n" , n);

   off = n - 1;

   for(i = 0; i < n; i++) {
printf("ret == %d\r\n", ret);
      switch(str[i]) {
      case '0':
      break;
      case '1':
         ret = ret + 1 * num[off-i];
      break;
      case '2':
         ret = ret + 2 * num[off-i];
      break;
      case '3':
         ret = ret + 3 * num[off-i];
      break;
      case '4':
         ret = ret + 4 * num[off-i];
      break;
      case '5':
         ret = ret + 5 * num[off-i];
      break;
      case '6':
         ret = ret + 6 * num[off-i];
      break;
      case '7':
         ret = ret + 7 * num[off-i];
      break;
      case '8':
         ret = ret + 8 * num[off-i];
      break;
      case '9':
         ret = ret + 9 * num[off-i];
      break;
      }
   }

   return ret;
}



short
main()
{
   short number;
   number = atoi("1234");
   printf("number == %d\r\n", number);
   return 0;
}
