implement atoi function

Write your own C program to implement the atoi() function

Comments

  1. int myatoi(const char *string)
    {
    int i;
    i=0;
    while(*string && (*string <= '9' && *string >= '0'))
    {
    i=(i<<3) + (i<<1) + (*string - '0');
    string++;
    // Dont increment i!
    }
    return(i);
    }

    ReplyDelete
  2. does (i<<3)+(i<<1) have any advantage over multiplying i with 10? or is it just another logic?

    ReplyDelete
  3. yes bitwise operation is faster than normal multiplication...

    ReplyDelete

Post a Comment

Popular posts from this blog