Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

put a print statement at the beginning of the function to print out the value of height_rect and width_rect. Are they what you would expect? If not then the problem is elsewhere in your program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 10 doesn't allocate room for the null terminator. Add 1 to the size() value.

Salem commented: Good catch +17
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The header file and line 62 of the *.cpp file are incorrect. The parameter you have declared is just one single character -- I know of no names that consist of a single character.
It should be this: void DisplayName (char* pFullName); or this void DisplayName (char pFullName[]);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

try this: obj.setvalue( &FB );

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Try redrawing the original graph with the same color as the background so that the lines will get erased, then draw the new graph.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
  • RegOpenKey() to open the key
  • RegEnumValue() to read the value directly into the string
  • CloseKey() to close the key object

Registry Fucntions here.

Example program here

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

DataReel.lib is free and portable to both *nix and MS-Windows. It has a huge amount of functions to do networking and other stuff.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

delete line 17 because it is a do-nothing line.

line 18 is pushing a pointer to an object that disappears from scope as soon as the function returns to main() -- the pointers are immediately invalidated. Why use a vector of pointers anyway? Just do this: vector<string> vect; and everything will work as you expect.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A KVM switch works very well, I've used it to control four computers with one keyboard, one monitor and one mouse. But don't expect them to last forever -- they wear out eventually and you will have to buy another one.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

xyz = *(long *)abc; That works when you KNOW that the character buffer contains the binary value of the long integer. For example

int main()
{
    char abc[10] = {0};
    long xyz = 123;
    memcpy(abc,&xyz,sizeof(long));
    long xxx = *(long *)abc;
    cout << xxx << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

as I said, the code I posted is untested. Here is correction which works. I removed the array of authors for simplicity, so you will have to add them back into the code.

void add(string title, string author, int nAuthors)
    {
	    // new node required
        book *q = NULL, *t = NULL;
	
        if (p == NULL)
        {
            p = new book;
            p->title = title;
            p->author = author;
		
            p->link = NULL;
            p->numAuthors = nAuthors;
        }
        else
        {
            book* save = NULL;
            q = p;
            while (q != NULL && q->title < title)
            {
                save = q;
                q = q->link;
            }
            t = new book;
            t->title = title;
            t->author = author;
            t->link = NULL;	
            t->numAuthors = nAuthors;
            if(save == NULL)
            {
                // add new book at the beginning of the
                // linked list
                t->link = p;
                p = t;
            }
            else
            {
                // add new book somewhere in the middle 
                // of the linked list
                save->link = t;			
                t->link = q;
            }

        }
     }
daniel88 commented: Pure, unadulterated genius. +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The code I posted is just an extraction of your post, after the else statement that begins on line 18. I added line numbers to your code so just refer to your original post.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If the list only needs to be sorted by book title then just insert new nodes in sorted order. I didn't test this but it should work something like below. You have to save a copy of the previous link when iterating through the list so that the program can back up one node. If you had a circular, 2-way linked list you wouldn't need to do that.

book* save = p;
q = p;
while (q->link != NULL && q->title < title)
{
      save = q;
      q = q->link;
}
t = new book;
t->title = title;
t->author = new string[nAuthors];
		
for (int i = 0; i < nAuthors; i++)
    t->author[i] = authors[i];
t->numAuthors = nAuthors;

save->link = t;			
t->link = q;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

still the same problem as before, but all you did was move it around a bit. What exactly are you trying to do ? I know you want to use double pointers but what is the object of the code you are posting ?

If you are attempting to create a 2d array then do it like this:

Example **object = new Example*[2];
for(int i = 0; i < 2; i++)
   object[i] = new Example;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It doesn't work because line line 23 object2 is a null pointer. The declaration on line 13 is hiding the declaration line line 6, so line 13 is not allocating memory for line 6. Also, line 15 is making the array of NULL pointers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When I consolidated all those 50+ globals into one *.cpp file I found several errors that had gone undetected, such as an integer with the same name had been declared globally in about three different files and god only knows what the compiler did to resolve that problem.

This program was written before function prototypes became popular. After taking the time to make a header file that contained all the function prototypes the compiler was able to identify several places in which function calls had either the wrong parameters or missing parameters. Function prototypes was another very major improvement.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

how about
% set path = ($path;.)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

18 years ago I got this nice new job and I had to take over maintenance of a C program that was written by someone else long gone. The program was written for MS-DOS 3.1 operating system and had about 20 *.c files with lots of global variables scattered around all those files. Maintenance of those files quickly became a nightmare because of all those globals so I consolidated them all into one *.c file. Globals were used to help speed up the program -- function calls in a computer that only ran 10 Mz or so is very very expensive so globals was one way to improve performance.

If that same program were written today I would have strangled the original programmer and just trashed the program.

jephthah commented: "strangled the original programmer and just trashed the program" ... i dont know how many times ive had that exact thought. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

here its about 112.6p - 122.9p for unleaded and 124.2p - 136.0p for diesel

thats for 1 litre! (a litre is only about 0.2 imperial gallons!)

122.9 x 5 = 614.5

614.5p is about 12 and a bit dollars.

so yeah, your estimate is a true possibility for us in the UK

If I were you I'd walk, ride a bike, or ride public transportation. It is $3.85/gallen here today where I live. But it has always cost a lot more in europe than in US.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is another way to do it

#include <iostream>
#include <algorithm>
#include <ctime>
using namespace std;

int main()
{

    const int maxnum = 10;
    int nums[maxnum] = {0};
    srand((unsigned int)time(0));
    int curnum = 0;
    for(int i = 0; i < maxnum; ++i)
    {
        bool found = false;
        do
        {
            int x = rand() % 50;
            int* result = std::find(&nums[0], &nums[maxnum-1], x);
            if( *result < 0)
            {
                nums[curnum++] = x;
                found = true;
            }
        } while( found == false);
   }
    for(int i = 0; i < maxnum; ++i)
        cout << nums[i] << "\n";

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are wanting to contain an array of unique random numbers, then

for each element in the array
    generate a random number
    search the array to see if the number already exists
    if not, then add it to the array
    otherwise, if it was found then go back and generate another number
end of loop

// something like this

const int maxnums= 10;
int nums[maxnums] = {0};
int curnum = 0;
for(int i = 0; i < maxnums; ++i)
{
    bool found = false;
    do {
       int  x = rand();
       for(int j = 0; j < curnum && found == false; ++j)
       {
            if( nums[j] == x)
            {
                found = true;
            }
         }
        if(found == false)
       {
            nums[curnum++] = x;
       }
    } while(found == true);
}
Run.[it] commented: Thank-you +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

My only question is why create a
MyParam*p
instead of a MyParam p ?

Because void* is a pointer and you can not case a pointer to a non-pointer. Pointers can only be case to other pointers.

but could you have cast to a MyParam and used . instead?)

Yes, but its more complicated (and looks ugly too) than just using the ->. And you have to do that every time you want to use it. cout << (*p).myvector1[i] << "\n";

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
struct MyParam_t {
  vector<double> *myvector1;
  vector<double> *myvector2;
};

Don't do that ^^^^ -- make the struct like you originally thought, see below.

struct MyParam {
  vector<double> myvector1;
  vector<double> myvector2;
};

void fn(void *ptr)
{
    MyParam*p = static_cast<MyParam*>(ptr);
    for(size_t i = 0; i < p->myvector1.size(); i++)
        cout << p->myvector1[i] << "\n";
}


int main(int argc, char* argv[])
{
    vector<double> d;
    d.push_back(1.0);
    d.push_back(2.345);
    MyParam p;
    p.myvector1 = d;
    fn(&d);
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are using cout then you can use setw()

#include <iostream>
#include <iomanip>
using namespace std;

int main(int argc, char* argv[])
{
    cout << setw(10) << "Hello";
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't recall seeing that problem, just the one I reported. Maybe the two are related ????

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I wrote this intending it to be either able to swap a structure, or just the data defined within a structure.

Will the swap function be able to do this, because.. when i tested it, it seemed to fail. but i didnt except it too.

It fails because all it does is swap the pointers within the swap() function itself because the pointers are passed by value, not by reference.

void swap(void** a, void** b)
{
    void* temp = *a;
     *a = *b;
      *b = temp;
}

Now the above will work ONLY if you pass a pointer to a pointer. It will also fail if you pass a pointer to some object.

int main()
{
    int a = 1;
    int b = 2;
    swap(&a, &b); // <<<<<<< wrong

    int* c = &a;
    int* d = &b;
    swap(&c, &d); // <<< OK
// when the swap returns, pointer c will point to b and pointer d will point to a.
// The value of [b]a[/b] and [b]b[/b] are still the same, only the two pointers
// were swapped

it should atleast work for swapping the data stored within the structure though, shouldnt it?

No.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

OMG am I happy that I use Microsoft Visual Studio. All that makefile stuff makes my head swim. :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Those ACM links are probably pretty useless to the OP. Not unless he has a Masters or Ph.D. in computer science or something which I doubt.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here are the files I compiled in .zip form. Just use winzip to uncompress them in the directory of your choice.
[edit]DaniWeb will not upload *.zip files, so I changed the filename to *.txt. After you download it, change the file back to *.zip and use winzip on it.[/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I did do as you said anyway now. I opened the .cpp and .hpp files in the browser and saved these files as textfiles. The project compiles except for the .ccp file.

That was a huge mistake. When you download the three files you have to click the Save button in the download window, not open it with the browser. From what I see in the text files you posted your browser added a lot of html code to the files that the c++ compiler doesn't know how to handle.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I download all three files and successfully compiled with with VC++ 2008 Express after making a couple changes.

  • name a.cc to a.cpp
  • have to add #include <limits> to each of the two *.cpp files
  • VC++ 2008 Express does not recognize and and or, so add these macros after the includes in each *.cpp file
    #ifndef or
    #define or ||
    #endif
    #ifndef and
    #define and &&
    #endif
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is the datafile.cpp that I get with the link posted by Duoas in post #17. As you see stdafx.h is not included here. I deleted most of the code to show only relevent parts. If there is a more recent copy then you should post it. Those text files you have posted are worthless because they are unreadable. Post the *.cpp file.

// datefile.cpp
// Copyright (c) 2008 Michael Thomas Greer.
//
// Boost Software License - Version 1.0 - August 17th, 2003
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

your project is using precompiled headers so the first line after the comments at the top of the *.cpp file must contain #include "stdafx.h" . If it doesn't eppear on the first line, add it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just compiled and ran your program in Dev-C++ and the window didn't close on me. I also ran it from command prompt and it worked there too.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to put a line at the end of main() to keep the window from closeing. Add a getchar() will do it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you have a lot of classes that can be used in several different projects then put the classes in a library or DLL. That way you only have to complie the classes once. Then you tell the compiler to link the application program, that includes main(), with the library. One way to do that is use the #pragma directive

// main.cpp
#include <string>
// other includes here

// force the compiler to link with your library
#pragma comment(lib,"mylib.lib")

>> If for instance u have 20 classes, u write all the code(classes) in the same environment, that in the same cpp file???

No. Each class can be in its own *.cpp file, and all the *.cpp files can be in the same project. A project can contain as many *.cpp files as you want. And in Visual Studio projects and contain other projects.

Traicey commented: U see what I was telling u +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Go to menu Tools --> Editor options, then select the General Tab. In the lower right-hand side is where you set the tab size. But you may also have to turn off Smart Tabs

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Instead of using the loops to initialize the array, you can also do it when the array is declared, like this: float a[M][M] = {0}; The above will initialize all elements of the array to 0.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you opened the file for reading, not writeing.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>ifstream ReadFile("C:\\File1.txt");
That is text mode. Here is binary mode: ifstream ReadFile("C:\\File1.txt", ios::binary);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

yes, ODBC is one way, and is supported by most, if not all, modern SQL compliant data bases. There are already several free odbc c++ classes. So what you are trying to do has already been done several times in the past 10 or so years.

For MySql specifically, you can download free MySQL++.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Thank you. I will look the seekg() method up in msdn.
You might find it there, but that is a standard c++ fstream function. Look here instead.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

By anime, do you mean animated ? If yes, the last one I watch and enjoyed was Ratatouille

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thank you. This seems to be a solution.
I might wonder one detail how it is possible to jump to a position in the file.

Let´s say I already know that I will read from the middle of the file (50 %).
How will I "jump" and begin to read from here.
What method could be used for this ?

call ifstream's seekg() method to move the file pointer to any location in the file. But you must know the byte offset.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Duoas's suggested binary search will work only if all the lines in the file are exactly the same length. If the length of the lines are different, due to the length of the number following the comma, then it won't work because you will not know the location of any given random line.

If you have the source code to the program that writes the entries in those files then it would help a lot if you would change it to write lines that are exactly the same length, even if it has to embed spaces or make the numbers after the comma padded to the left with 0s so that they are all the same length

01/01/2008,0001
01/02/2008,0002
01/03/2008,0003
01/04/2008,0004
01/05/2008,0005
01/06/2008,0006
01/07/2008,0007
// etc
01/07/2008,9999

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Convert the dates to time_t using struct tm in <ctime> then you can easily compare the two dates without any problems. Or, you can rearrange the date so that they are in the form YYYY/MM/DD then you can use normal string comparisons on the dates.

>>So is it possible to search for an entry and an exitpoint in this file instead of reading the file from top to bottom ?

Depends. If the file is sorted by date, then you start from the beginning of the file and keep reading until the last date that you want has been read. At that time the program can stop reading the file. Its not possible to jump directly to the beginning of the dates that you want.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm confused -- you want to write a c++ SQL class but you don't know the SQL language yourself ??:icon_eek:

Maulth commented: Thank you for helping me with my ODBC problem :D +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you are making a mountain out of a molehill. Your code is much too difficult.

//Creating my class members
    ifstream infile;
    Rocket ship;
    
    //My arrays initialized to 0
    float alltime [7528] = {0};
    float allheight [7528] = {0};
    float allv [7528] = {0};
    float alla [7528] = {0};
   
    //Creating my most excellent arrays
    int i = 0;
    while (i < 7528 && infile >> alltime[i] >> allheight[i] >> allv[i] >> alla[i])
         i++;
t = t+4;
          h = h+4;
          v = v+4;
          a = a+4;

Although you don't need the above code, to answer your question all you have to do to increment pointers of any size is this:

t++;
          h++;
          v++;
          a++;
marti3a3 commented: The moderator helped me see a way of writing code that I had completely passed. Thanks! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Most are telling me either i can't access the private member variable IDs or the other member variables i'm attempting to access

private means just exactly that -- only the class itself can access private members. Work around: write get() and put() public methods to make private members available outside the class

class CorporateClass {
public:
    CorporateClass(int I): ID(I) { }//contstructor method
    CorporateClass(){} //constructor method

    void initialize(ifstream text, float &, float &, float &);
    void div_update(float, float, float);
    void add_credit(ifstream text, float &, float &);
    void ded_debit(ifstream text, float &, float &);
    void HQset();

// get methods
    int getID() { return ID; }
    // etc for all other private members you want to
    // give public access

// put methods
    void putID(int id) {this->ID = id;}
// etc for others

private:
    int ID; //4 digit int values
    float balance;
    float credit;
    float debit;
};

Now you can use the put() and get() methods in main

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post the declaration of details