Thread: Integer into a String ????

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    53

    Integer into a String ????

    how would you get an integer into a string ?

    For example

    Code:
    int main()  {
      int temp,temp2;
      char string[20];
    
      printf("please enter an integer\n");
      scanf("%d",&temp);
      temp2=temp;
    
      string=temp2;    /* Here's my problem */  
      
    }
    It has got to be done this way. I cannot get away from it at all. Any help would be appreciated.

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    itoa(temp2,string,10);

    itoa takes 3 arguments: a number, a character array, and the base, which is usually base 10.
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    sprintf( buffer, "%d", number );

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  2. Integer to string?
    By Blackroot in forum C++ Programming
    Replies: 2
    Last Post: 02-23-2006, 06:13 AM
  3. Conversion of character string to integer
    By supaben34 in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2003, 04:34 AM
  4. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 10:32 AM
  5. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM