AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answers »

  1. Submitted By: rice — October 6, 2006
    +11 votes
      + -

    int str2int(const char *str)
    {
    int value = 0;
    int sign = (str[0] == ‘-’)?-1:1;
    int i = (str[0] == ‘-’)?1:0;
    char ch;

    while(ch = str[i++])
    {
    if ((ch >= ‘0′)&&(ch <= ‘9′))
    value = value*10 + (ch - ‘0′);
    else
    return 0;
    }
    return value*sign;
    }

  2. Submitted By: Tachyon — October 6, 2006
    -2 votes
      + -

    #include <stdio.h>
    int strtoint(char *s)
    {
    int index = 0, flag = 0;
    while( *(s+index) != ‘’)
    {
    if( (*(s + index) >= ‘0′) && *(s + index) <= ‘9′)
    {
    flag = 1;
    index++;
    }
    else
    {
    flag = 0;
    break;
    }
    }
    if( flag == 1 )
    return atoi(s);
    else
    return 0;
    }

    main()
    {
    printf(”%d”,strtoint(”0123″));
    printf(”n%d”,strtoint(”0123ii”));
    }

  3. Submitted By: MachinShin — October 6, 2006
    -3 votes
      + -

    #include <iostream>
    #include <string>
    #include <sstream>

    using namespace std;

    int returnInt ( string &str )
    {
    stringstream s ;
    s << str;
    int p;
    if ( s >> p )
    {
    return p ;
    }
    else
    {
    //technically, this should throw an exception :)
    cout << “Not A Number!”<< endl ;
    return 0 ;
    }

    }

    int main ()
    {
    string s;
    cout << “input a #” << endl ;
    getline (cin, s ) ;
    int p = returnInt ( s ) ;
    cout << p ;
    return 0 ;
    }

    sigh,i love the power of the c++ standard libraries :)

  4. Submitted By: JavaVersion — February 4, 2007
    -2 votes
      + -

    private static int strToInt(String s){
    int result=0;
    for(int i=0;i=’0′&& c

  5. Submitted By: jijiduru — March 8, 2007
    -3 votes
      + -

    you guys haven’t heard of isDigit? It’s in standard ANSI C :)

  6. Submitted By: Lev — September 9, 2007
    not yet rated
      + -

    You should also consider the output number to be bigger than 4gb, therefore you should test for length of string, and that the str[0] (or str[0] in case has a sign) is

  7. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.