Convert a number from string to integer without using inbuilt function

Posted by Raja on Stack Overflow See other posts from Stack Overflow or by Raja
Published on 2011-03-13T15:55:07Z Indexed on 2011/03/13 16:10 UTC
Read the original article Hit count: 172

Filed under:
|

I am trying this technique but error is coming. Please help me to convert a number from string to integer.

#include<iostream>
using namespace std;

int main()
{
    char *buffer[80];
    int a;

    cout<<"enter the number";
    cin.get(buffer,79);

    char *ptr[80] = &buffer;
    while(*ptr!='\0')
    {
        a=(a*10)+(*ptr-48);
    }
    cout<<"the value"<<a;

    delete ptr[];

    return 0;
}

Errors are:

  1. error C2440: 'initializing' : cannot convert from 'char ()[80]' to 'char *[80]'
  2. error C2440: '=' : cannot convert from 'char *' to 'int'

© Stack Overflow or respective owner

Related posts about c++

Related posts about homework