Thread: I need a type of variable that uses however much range needed

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    60

    I need a type of variable that uses however much range needed

    I am making a simple typecast program that converts an integer (not the variable type) into a string but typecasted. The integer is too big to store in an int or long or double. Is there any way to make the range of the variable the_value_inputted to the_value_inputted the moment the variable is inputted. or is there any way to make a string act as a really long integer. I want to make a converter that decodes ASCII messages into strings but the integer of the ASCII Messages are reallly long. strings provide any length (or maybe a really long length) to be inputted.
    Child who knows C++
    Using Borland C/C++ Compiler 5.5 (Command Line Version)

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    I really dont completely understand what you want to do...

    So you want to take a number and turn it into the ASCII equivalent?

    an int is 32bits long I believe, and if thats too much..

    how bout a char or unsigned char

    If I am completely missing the point, I am sorry, try talking to me like im 2

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I think I understand what you are trying to do.

    Say the user inputs 8 billion, well its too large to store in 32 bits.

    How about using std::string to store the number it will be one of the easist to resize as needed

    btw an int is not always 32 bits.

  4. #4
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Quote Originally Posted by Thantos
    btw an int is not always 32 bits.
    Ah, really, I suppose its compiler dependant?

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    IIRC here are guidelines in the standard but they specify the min values. The max values are set by the compiler and the system

  6. #6
    C++ n00bie :D
    Join Date
    Jul 2004
    Posts
    63
    If you mean converting the int value of a string to char form, I understand Heres a way I used for it.

    Make two functions. One will tell the program how many int values to input, and the other, run by the first, will convert it. ie:
    Code:
    void convert(int length, ...) {
      va_list arguments;
      va_start(arguments, length);
      for (int x=0; x<length; x++){
        std::cout<<(char)va_arg(arguements, int);
      }
      va_end(arguments);
    }
    
    void itos(int argn) {
      if (argn == 1) convert(ary[0], ary[1]);
      if (argn == 2) convert(ary[0], ary[1], ary[2]);
      .
      .
      .
    }
    The array is the message broken up. [0] is the amount of chars, inother words when declaring itos(int to string) use ary[0] for its declare so it uses the right amount. Everything after [0] is the individual chars in int form. I just did this earlier myself

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-26-2009, 08:54 AM
  2. Conversion of pointers to functions
    By hzmonte in forum C Programming
    Replies: 0
    Last Post: 01-20-2009, 01:56 AM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM