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

When I click a link IE8 always opens a new window instead of creating a new tab. I have clicked Tools --> Internet Options --> Tabs --> "Open Link In Other Programs In" --> "A new tab in current window".

How can I set it so that a new tab is created instead of opening a new window? Or maybe its not possible?

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

There is no such thing as space that is absolutely empty. space by definition contains something. And in a vacuum there is no space.

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

You could go to your CONTROL PANEL --> Edit Options and uncheck this option box. Other than that there is little that we can do about it.

you can allow other members to send you email messages.
[ ] Receive Email from Other Members

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

maps only take two values. For your purposes one value can be a structure that contains the two numbers you want.

map<vector<int>, std::string> theList;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The same way std::string does it

class String
{
	public:
		String();
		String(char *str);
		~String();

		String& operator= (char *str);
		operator char* ();
        const char* c_str() {return szStr;} 
		bool operator== (char *str);

	private:
		char *szStr;
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I tried to compile it with vc++ 2008 express and got other errors. Must be some header files missing -- I have no idea how to correct them.

1>c:\dvlp\test2\test2\debug\msado15.tlh(2375) : error C2059: syntax error : '<L_TYPE_raw>'
1>c:\dvlp\test2\test2\debug\msado15.tlh(2375) : error C2238: unexpected token(s) preceding ';'
1>c:\dvlp\test2\test2\test2.cpp(27) : error C2065: '_RecordsetPtr' : undeclared identifier
1>c:\dvlp\test2\test2\test2.cpp(27) : error C2146: syntax error : missing ';' before identifier 'pRstAuthors'
1>c:\dvlp\test2\test2\test2.cpp(27) : error C2065: 'pRstAuthors' : undeclared identifier
1>c:\dvlp\test2\test2\test2.cpp(30) : error C2065: 'pRstAuthors' : undeclared identifier
1>c:\dvlp\test2\test2\test2.cpp(30) : error C2228: left of '.CreateInstance' must have class/struct/union
1> type is ''unknown-type''
1>c:\dvlp\test2\test2\test2.cpp(30) : error C2065: 'Recordset' : undeclared identifier

<snip>

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

Those links at the top leads me to believe this is just a cheap attempt to spam and yes if you look at his post history that confirms it.

spamy links don't necessarily make the entire post spam.

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

<map> doesn't allow duplicates. And with map you don't even need that structure, unless it contains other things that you didn't post here.

Example code here.


std::set container also don't allow duplicates and are sorted.

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

Isn't that the same thing I posted? That is, they are both magic numbers.

I think one way to write a program to find them is to read each line of the file and search it for a digit (0-9). If a digit is found, then most likely it will be the beginning of a magic number.

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

what do you mean by magic numbers?

Example: int i = 123; the "123" is considered a magic number. Is that what you mean?

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

I compiled and ran your program on 64-bit Vista. This is the results

Initializing.....Done
Opening results.txt.....Success
Scanning numbers.....Finished
Building pair list.....Finished.
Statistics were saved in pairs.txt
Press any key to continue . . .

I did not run the exe file in your zip file.

>>but I tried it on two different computers running XP, and it doesnt work =(

What exactly do you mean by "it doesn't work"? Did you compile your program for debug or release. If for debug then the other computers more than likely do not have the correct Microsoft debug DLLs. Compile for release mode and try it again.

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

Quick, before the mods get here! Add the code tags !

Its not really worth the effort :)

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

post the data file.

>>or could it be because of the x64 cpu?
Unlikely. I'll let you know when you post the data file.

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

Thank you very much! I repaired according to Ancient Dragon's idea, and ok! But I still want to know why my code I posted has got error. Can you help me, please?

Explained in post #7 of this thread.

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

I guess its time for you to toss what you've done into the bit bucket and do it again the right way.

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

The code you posted appears to contain a memory leak. You don't have to worry about destroying those vectors because the vector class will destroy itself when the class or program terminates.

If s1, s2 and s3 are being allocated somewhere else with new operator, then you need to delete them after push_back() is called (after line 19 of the code snippet you posted).

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

Initialize your sudoku like this:

int sudoku[9][9] = {
  {0,0,0, 0,0,0, 0,0,0},
  {0,0,0, 0,0,0, 0,0,0},
  {0,0,0, 0,0,0, 0,0,0},

  {0,0,0, 0,0,0, 0,0,0},
  {0,0,0, 0,0,0, 0,0,0},
  {0,0,0, 0,0,0, 0,0,0},

  {0,0,0, 0,0,0, 0,0,0},
  {0,0,0, 0,0,0, 0,0,0},
  {0,0,0, 0,0,0, 0,0,0}
};

Good grief! initialize the array like this: int sudoku[9][9] = {0};

Nick Evan commented: Haha :) +18
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

hiscasio: also tell us what compiler you are using. And are you on *nix, MS-Windows, or something else?

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

Stay away from those pointers.

lines 8-10: delete those lines

lines 16-18:

p.push_back(string("s1")) ;
p.push_back(string("s2")) ;
p.push_back(string("s3")) ;

With the above changes you don't have to worry about a destructor because the vector and string classes with destroy themselves.

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

Its used by M$ compiler to produce pre-compiled headers, which can greatly speed up the compiling process on large multi-file *.cpp projects that all need the same header files. stdafx.h has little if any value on single *.cpp file projects.

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

lines 13-40 do the same thing over and over for 81 times!:icon_eek: What's the point of doing that?

delete line 12 because lines 13-40 initialize the array with other numbers.

lines 61 and 64: what is comp false; ? There is no such thing as comp

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

where is file header file "stdafx.h" ??? can u post that file code as well... :)

stdafx.h is a standard Microsoft IDE-written header file. Hopefully the op of this thread has added proper STL headers to that file, such as <ifstream>. The program would not compile if that were not the case.

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

why did you bother creating that pointer just to pass to a function? All you have to do is pass string's c_str() WriteFile(str.c_str()); >>line #9: cin.widen('\n')
What is that supposed to do -- unless you compile for UNICODE it will do nothing. Seems more reasonable to just do this: getline (cin,str); and let getline() do its job.

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

>>If You Want Something To Do, Try This Exercise...
Ok, wrote, compiled and debugged in 22 minutes. Except I used a linked list instead of an array. (This is my day off from work so I have lots of time to spare :) )

tux4life commented: LOL :D +7
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Sorry about that, you are right, variable i is a mistype

while( RowsRead < ARRAYSIZE &&
   in >> names[RowsRead] >> id[RowsRead] 
       >> age[RowsRead] >> gpa[RowsRead] )
{
     ++RowsRead;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>However, have you changed your binary file back to the txt file?
Yes, and both files were exactly the same (other than one being text and the other binary).

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

template <class T>
bool getnum(ifstream& in, T& num)
{
    in.read((char*)&num, sizeof(T));
    if( in.gcount() != sizeof(T))
    {
        cout << "Read error\n";
        return false;
    }
    return true;
}

int main()
{
    ifstream in1("data.txt");
    ifstream in2("data.bin", ios::binary);

	int index1;
	int index2;
    int i = 0;
	float simvalue;
    while( in1 >> index1 >> index2 >> simvalue )
    {
        int a, b;
        float c;
        if( !getnum( in2, a) || !getnum( in2, b)
            || !getnum( in2, c) )
        {
            cout << "read failed on line " << i << "\n";
            break;
        }
        ++i;
        if( a != index1 || b != index2 || c != simvalue)
        {
            cout << "Values are not the same\n";
            cout << a << " " << index1 << "\n";
            cout << b << " " << index2 << "\n";
            cout << c << " " << simvalue << "\n";
            break;
        }
        if( (i % 16000) == 0)
            cout << i << "\n";
    }
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> while (a != password)

Just for completeness, the above line should be written like this: while( password[0] != a ) That will remove the error, but not the logic of why you would want to code something like that. What about all the other characters the user typed?

If you want to compare the password you type with some pre-determined password then do something like this:

char password[31] = {0};
do
{
    cout << "Enter password\n";
    cin.getline(password, sizeof(password));
} while( strcmp(password, "abcdefg") != 0);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Probably not more than one in a thousand could name more than a couple of the MEPs we sent there last time.

Its like that here too. Very few American's can name the people in our Congress and Senate. Sure I know the names of a few, but all 600+ people?

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

If you post something in the wrong forum, just hit the "Flag Bad Post" blue link and request a mod to move it to somewhere else. We realize people are not perfect and sometimes make mistakes. You will not get any grief from any of the moderators if you ask us to move your thread, unless of course you want it moved to an inappropriate forum.

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

you will need four arrays, one for of the columns in the file.

const int ARRAYSIZE = 1000;
char names[ARRAYSIZE][1];
int id[ARRAYSIZE] = {0};
int age[ARRAYSIZE] = {0};
float gpa[ARRAYSIZE] = {0};
int RowsRead = 0;
ifstream in("file.txt");
while( RowsRead < ARRAYSIZE &&
   in >> names[i] >> id[i] >> age[i] >> gpa[i] )
{
     ++i;
}

// now all the rows in the file are in memory. When you sort the rows you have to swap the rows in all four arrays so that they are kept in sync with each other.

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

There is no such thing as a 30% chance of pushing -- either its pushed or it isn't. I suppose you could generate a random number between 0 and 1 and if it is greater than 0.3 then push it.

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

If you have to write your own sort function, google for "sort algorithms", or for "bubble sort"

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

That doesn't make sense either. Suppose vector.size() == 0 (an empty vector). 1/1 = 1. So are you going to push something onto the vector or not? If yes, then the next item will be 1/(1+1) = 1/2 = 0.5. Again yes. Third time is 1/3 = 0.3323. No can push. That means only 2 items can be pushed onto the vector.

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

probability of what? Apples are red? Sky is blue? Grass is yellow?

How is the probability variable calculated? Just a random number? So you want to increment the counter if there is a 50-50 chance of something happening?

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

If you read all that data into memory at the beginning of the program you can then write a simple function to display the information.

  1. create a structure that contains each of the fields in the file
  2. read the file into an array of structures
  3. use std::sort() to sort the structures by name
  4. display the data
  5. use std::sort() to sort the structures by gpa
  6. display the data
  7. perform other calculations to get class average etc.

Sorting the array of structures is only one line of code! No need to write all that complicate sort algorithms yourself, unless your instructor told you to. The entire program can be done in about 100 lines of c++ code, so if you are writing more than that you are writing too much code.

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

what is SDL ?
where is socket.h?

I need to compile and run your program is you expect my help.

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

Look in your textbook for class constructors. What I posted is called inline code. Or you can find more info online.

That header file has similar problems with all the other methods of that class. You have to write code that implements all those methods, or get the code from who ever you got that header file.

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

You failed to write the Array class's constructor implementation code.

#ifndef ARRAY_H
#define ARRAY_H

#include <iostream>
using namespace std;

template < typename B >
class Array
{
	friend ostream &operator << ( ostream &, const Array < B > & );
	friend istream &operator >> ( istream &, Array < B > & );
public:
	Array ( int x = 10 )

       {
             color = x;
             ptr = 0;
       }
	Array ( const Array & a )

       {
             color = a.color;
             ptr = a.ptr;
       }

	~Array ( );
	int getSize ( ) const;

	const B &operator = ( const Array & );
	bool operator == ( const Array & ) const;

	bool operator != ( const Array &right ) const
	{
		return ! ( *this == right );
	}

	B &operator [ ] ( int );
	B operator [ ] ( int ) const;
private:
	int size;
	B *ptr;
};

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

>>memset(wText,0,len);
That only sets the first half of the buffer -- what you want is memset(wText, (len * sizeof(wchar_t)); >>should I create a new pointer to convert from the unsigned char[]?
No, just typecase it: int len = strlen((const char *)in)+1

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

Now I understand, the problem is when you press F5 to start debugging. The Ctrl+Z sets some flags in cin that have to be cleared in order to get cin.get() or cin.ignore() to work properly.

cin.clear();
    cin.sync();
    cin.ignore();
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you don't know what those functions are then we won't be able to help you. Multiply() is a method of class Natural_Number_1_C. So you have to read the header file Number_1_C.h to find out what they do.

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

I used VC++ 2008 Express and it worked for me (see bitmap in my previous post).

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

And how, prey tell me, do you expect to enter your name and grades without a console window? What did you expect to see? Below is what I see when I run the program

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

definitely it's the crappiest program language...

c++ is not a crappy programming language -- the program you have to "enhance" is crappy. IMHO your teacher is an idiot. But that's neigther her nor there.

Your immediate problem is that you posted calls to functions that are non-standard in c++ language so you need to post those functions too. Otherwise no one can tell you the answer to your question.

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

Ctrl+F5 does not produce the eof signal the program is looking for. EOF is produced with Ctrl+Z key combination.

>>when I compile in release mode and run the exe it opens it in debug mode (or the same as the command line when you run as debugging)

Its supposed to do that because its a console program. That's a console window you see, not a debug window.

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

variable password is only a single character, which means it will accept only one character. If you want it to accept many more characters then declare it as an array of characters, or a std::string object, like this: char password[255] = {0}; . That lets you type up to 254 characters as the password.

[edit]^^^ I'm too late :) [/edit]

tux4life commented: But your info is excellent! +7
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Have no idea how to help you because I don't know what Multiply() and Power() do.

And that is one of the weirdest programs I have seen in a long long time. program_body instead of int ??? Only a university professor would dream of writing such confusing and unconventional crap.

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

Page not found?

try the links again -- they worked ok for me.

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

post a small example program that has the problem you describe because I don't quite understand what you are talking about.

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

I wrote this program to generate the text file

int main()
{
    srand( (unsigned int)time(0));
    double x = 0;
    ofstream out("data.txt");
    for(int i = 0; i < 8000000; i++)
    {
        x = (double)rand() / (double)RAND_MAX;
        out << i+1 << " " << i+7000 << " " << x << "\n";
        if( i > 0 && (i % 100000) == 0)
           cout << i << "\n";
    }
}

And this one to convert it to bin file

int convertForth(char* asciifile, char* binfile);


int main (int argc, char* argv[])
{

    convertForth("data.txt", "data.bin");

}

int convertForth(char* asciifile, char* binfile){

	cout << "converting forward" << asciifile << "->" << binfile <<endl<<flush;

	ifstream infile (asciifile);

    ofstream outfile (binfile, ios::binary);


    time_t t1, t2;
	int index1;

	int index2;
    int i = 0;
	float simvalue;
    t1 = time(0);
    while( infile >> index1 >> index2 >> simvalue )
    {

        outfile.write((char *)&index1, sizeof(index1));
        outfile.write((char *)&index2, sizeof(index2));
        outfile.write((char *)&simvalue, sizeof(simvalue));
        if( i > 0 && (i % 100000) == 0)
           cout << i << "\n";
        i++;

    }

	infile.close();
	outfile.close();
    t2 = time(0);
    cout << "Execution time: " << t2 - t1 << " seconds\n";
   return 0;
}

The original text file was 200 meg and the bin file 94K. The second program took 112 seconds to convert from text to binary.

With an 800meg text file you might want to check your hard drive to see if it contains sufficient space to write out the data. Your description of the problem sounds like your hard drive might be …