morning everyone.
i hope someone out there could really help me.
im trying to store large numbers. as i need to complete my work under Dev-c++ environment but im not familiar with it as i just started using it recently.
the following is my initial coding for my work.

/*This is a program to calculate large numbers.*/

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "Stack2.cpp"
#include "Draft2.h"

using namespace std;
 int atoi(const char *number2); 
int main()
    string number1,number2,num;
    int i,j,x;
    int length;
    int comma=0;
    int Digit=0;
    int value;
    cout << "Enter integer: ";
    cout<<"Total digit: "<<length<<endl;
    while (number2[x]!='\0')
        //if (isdigit(number2[x]))
    system ("PAUSE");
    return 0;  

int atoi(const char *number2)
    int value1;
    return value1;

after i compile using Dev-C++, it shows this error description:
invalid conversion from 'char' to 'const char*'
initializing argument 1 of 'int atoi(const char*)'
i've tried all ways to modify my coding but i just cant get it.
really would be happy if someone could help me.
hope to receives some replies as soon as possible.thank you.

Recommended Answers

All 5 Replies

My guess is the problem is in stack2.cpp. But since you did not post it there is no way to tell. Also please post the exact error message including file and line number

Hi ,

invalid conversion from 'char' to 'const char*'
initializing argument 1 of 'int atoi(const char*)'

int atoi(const char *number2)

This function expects pointer as argument but you are passing a character .

so pass the address of that character as


Parthiban's suggestion to pass the address of each character of number2


is not quite going to do what it appears you think the atoi() function is doing for you.

atoi( ) give the integer value of the "string" pointed to by the char*. So, if number2 holds
"12345" as you pass it each character's address, in turn, your loop (lines 31-37) will give the results:

If you want the value each character represents, simply subtract from each character the character '0' (zero).

    while (number2[x]!='\0')
        if (isdigit(number2[x]))
              value = number2[x] - '0' ;
              cout << value << endl;

Also, using the NULL terminator to test for end of string with the string type is not strictly defined. The presence of the NULL ( '\0' ) is not a requirement of strings, and may not be supported in every compiler. Why not use a for loop, based on number2.length(), as you already have used earlier?

Also, why are you defining atoi()? It already exists. And, as you've defined it, it's recursive with no ending.


thank you vmanes.i've used your method as:

value = number2[x]-'0';

and it works.
thanks alot.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.