storing and printing doubles
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: storing and printing doubles

  1. #1
    Join Date
    Feb 2004
    Far East

    storing and printing doubles

    Below program was originally meant to receive any type of data, store them and then print them on the console. In the function add() the value to be stored, stored as one byte a time.
    As an exercise I have to change it a bit to store 25 double values and then print them. But now itís not functioning correctly. After storing the 25 numbers all I get is a bunch of zeros as the output at the console. Please could you give me a hint about whatís the wrong.
    // implementation file
    const int increment = 100;
    void Stash::initialize(int sz)
    	size = sz;
    	quantity = 0;
    	storage = 0;
    	next = 0;
    void Stash::add(const void* element)
    	int startBytes = next*size;
    	unsigned char* e = (unsigned char*) element;
    	for(int i=0; i<size; i++){
    	storage[startBytes+i] = e[i];
    void Stash::print()
    	for(int i=0; i<=25; i++)
    void Stash::inflate(int increase)
    	int newQuantity = quantity + increase;
    	int newBytes = newQuantity * size;
    	int oldBytes = quantity * size;
    	unsigned char* b = new unsigned char [newBytes];
    	for(int i=0; i<oldBytes; i++)
    		b[i] = storage[i];
    	delete []storage;
    	storage = b;
    	quantity = newQuantity;
    // main method
    void main()
    	Stash s;
    	for(double d=0; d<=25; d++)
    Thanks a lot for reading.

  2. #2
    Join Date
    May 2000
    Washington DC, USA
    where are you allocating storage?

    post the class definition .h file so we can run it..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center