atoi?

This is a discussion on atoi? within the C++ Programming forums, part of the General Programming Boards category; hi char * temp=new char[200]; temp[0]=1; temp[1]=9; temp[2]=5; temp[3]=3; then if i call cout<<(atoi(temp)) it prints 0. how can i ...

  1. #1
    Registered User mayfda's Avatar
    Join Date
    Apr 2002
    Posts
    11

    atoi?

    hi
    char * temp=new char[200];
    temp[0]=1;
    temp[1]=9;
    temp[2]=5;
    temp[3]=3;

    then if i call
    cout<<(atoi(temp)) it prints 0.

    how can i convert temp to an integer?

  2. #2
    Registered User mayfda's Avatar
    Join Date
    Apr 2002
    Posts
    11

    Unhappy ?!?

    still it is same althoug i did the things you say?
    -mayfda-

  3. #3
    Bios Raider biosninja's Avatar
    Join Date
    Jul 2002
    Location
    South Africa
    Posts
    765
    cout<<(atoi(temp)) it prints 0.
    cout << atoi(temp[x]);

    where x is the number in the array (1,2,3,4....200)

  4. #4
    Registered User mayfda's Avatar
    Join Date
    Apr 2002
    Posts
    11

    Exclamation hmm

    cout<<atoi(temp[x]);
    i tried x=1
    invalid conversion from `char' to `const char*'
    -mayfda-

  5. #5
    Bios Raider biosninja's Avatar
    Join Date
    Jul 2002
    Location
    South Africa
    Posts
    765
    Ok I tried this :

    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <stdlib.h>
    
    int main()
    {
    	char * temp=new char[200];
    	temp[0]='1';
    	temp[1]='9';
    	temp[2]='5';
    	temp[3]='3';
    
                    cout << atoi(&temp[1]);
    
       getch();
    
    	return 0;
    }
    works, but it displays the value and every value in the array after the one I wanted

  6. #6
    Registered User mayfda's Avatar
    Join Date
    Apr 2002
    Posts
    11

    nop

    int main()
    {
    char * temp=new char[200];
    temp[0]='1';
    temp[1]='9';
    temp[2]='5';
    temp[3]='3';

    cout << atoi(&temp[1]);

    getch();

    return 0;
    }

    but i want to return whole number in here it is
    1953
    -mayfda-

  7. #7
    Registered User mayfda's Avatar
    Join Date
    Apr 2002
    Posts
    11

    upppps

    i found the problem it is becouse of wrong pharantese organization
    -mayfda-

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble with atoi
    By NewbGuy in forum C Programming
    Replies: 2
    Last Post: 05-22-2009, 11:55 PM
  2. help with this
    By tyrantil in forum C Programming
    Replies: 18
    Last Post: 01-30-2005, 03:53 PM
  3. Problem with atoi in C
    By garagebrian in forum C Programming
    Replies: 5
    Last Post: 08-24-2004, 01:59 PM
  4. string to int conversion not using atoi()
    By linucksrox in forum C Programming
    Replies: 2
    Last Post: 05-19-2004, 12:17 AM
  5. how to use atoi!!!
    By moon in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2002, 08:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21