nucleon 114 Posting Pro in Training

sid> But what annoyed me really was the reply of Nucleon.

Sorry if I made you cry, sid, but if my post imitating your style annoyed you, imagine how your original post felt to the OP. Are you getting it now? Do you see the point?

narue> boyscout

Actually, since I don't believe in invisible people (hence the "atheist atom" symbol), I can't be a boyscout! (BTW, my opinion of Narue is very high. I think she's great. And, as you'll see, I'm not just sucking up.)

AD> Enough of the personal insults. The next one will get a nasty infraction.

That is absolutely ridiculous! Moderators' time is better spent telling people not to tell lies. And what about sid's original personal insults to the OP? Of course, that's okay! No reprimands for sid! He's just the greatest! Why don't you give him yet more rep? Obviously he's the kind of person that Daniweb wants!

To all:

In my opinion, someone who helps others should have three qualities:
1. Know the subject (and their own limitations).
2. Explain things clearly (and carefully read what others say).
3. Be nice. (Why not?)

Number 1 is straightforward. Programming is not an arcane art but an engineering discipline. A major design criterion in any programming language is ease and practicality of use. Knowing how to program doesn't make you a genius, no matter what your mommy says. ("Oh siddy, my little genius!")

William Hemsworth commented: Cya +9
nucleon 114 Posting Pro in Training

sidiot> You won't see 'this' me in [other] posts
sidiot> If I was rude in this thread, it was for a reason.

This is simply a lie. There was absolutely no "reason" to be rude. Not only was the sidiot rude, he was also wrong!

He doesn't bother to properly read and understand other people's posts. He assumes everyone is stupid. "Who are you to question me?" he says (and he says this to me when I'm correcting his obvious error). This bespeaks a deep psychological problem, one we are not about to solve here.

The fact is that the sidiot is total jerk. If he's going to continue lying we can keep this thread on the front page for a month; then everyone can see what a jerk he is.

(He'll probably even respond to this post. What a sidiot!)

tux4life commented: Don't provoke him :angry: !! +0
nucleon 114 Posting Pro in Training

> I used that before, but ran into many problems.

It's still the way to go. Try out this program:

#include <stdio.h>

#define SIZE 100

int main()
{
    char inbuf[] = "w 1 1 12 hello world";
    char c, s[ SIZE ];
    int d1, d2, d3;
    sscanf( inbuf, "%c %d %d %d %[^\n]", &c, &d1, &d2, &d3, s );
    printf( "%c\n%d\n%d\n%d\n%s", c, d1, d2, d3, s );
}
nucleon 114 Posting Pro in Training

This: void FindcarVin(int , string , string, int , int ); is not the same as this: void FindcarVin ( int vinnums[], string brandnames[], string modelnames[], int yearnums[], int specnum ) See the difference? It's always best to copy the definition's signature, both to ensure the prototype is the same and also it's useful to have the variable names even in the prototype (since this is all one will see in a header file).

nucleon 114 Posting Pro in Training

I forgot that you will need to pass in the size of the array as well (unless you can change it to a vector). Here's the idea:

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

struct Car
{
    int vin;
    //etc.
};

void showVins( const Car* car, size_t size );

const int SIZE = 30;

int main()
{
    Car car[ SIZE ];
    
    ifstream infile( "usedcars.txt" );
    if( !infile )
    {
        cerr << "Cannot open file\n";
        exit( -1 );
    }

    size_t size = 0;
    while( (size < SIZE) && (infile >> car[ size ].vin) )
    {
        // etc..
        ++size;
    }

    infile.close();

    showVins( car, size );
}


void showVins( const Car* car, size_t size )
{
    for( size_t i = 0; i < size; ++i )
    {
        cout << car[ i ].vin << endl;
    }
}
nucleon 114 Posting Pro in Training

The only line that looks like it might set up the error (through undefined behavior) is this: unidata.maxval=getMaxval(argv[1]); .

Presumably this function is in iplib2New.c. BTW, you're including the code file. Normal practice is to include a header and link with the object (or library) code.

nucleon 114 Posting Pro in Training

I don't understand the question. Perhaps if you describe what you are trying to do. In general, people seem to be overusing strtok. Often it's not the way to go. Your's looks like a job for sscanf or fscanf, but it is hard to tell without more info.

nucleon 114 Posting Pro in Training

Oops. Looks like I gave you the wrong prototype. Try: void findvin( const Car* car ); Also, remember to use SIZE and not the number 30 in you code (since that's what SIZE is for).

nucleon 114 Posting Pro in Training

Instead of a bunch of parallel arrays like this:

int vin[SIZE]; 
string brand[SIZE];
string model[SIZE];
int year[SIZE];
int mileage[SIZE];
double mpg[SIZE];

try a single array of structs like this:

struct Car
{
    int vin;
    string brand;
    //etc.
};

Car car[SIZE];

And all your function signatures become: void findvin( const Car& car ); Much neater!

As for your errors, the thing to do first is to print out the data right after you've read it in. I suspect you have not read it in properly.

nucleon 114 Posting Pro in Training

Minimally you must handle single quotes, double quotes, single-line comments, and multi-line comments, since, as ArkM has pointed out, these constructs may contain parens (etc.) which you will want to ignore.

nucleon 114 Posting Pro in Training

> the lack of any apparent connection makes me think i'm initiating
> something else (one of the libraries or something from the OS)
> that has a run-time error

Although possible, you should consider this as a last resort. Otherwise it will dull your mind to the more likely possibility that it is, in fact, your code that has the error.

If your code compiles, as you say it does, then clearly there is nothing in the code you posted that could produce the error (besides read_pnm, which we shall assume for the moment to be okay).

So you need to post more code. If there's a lot, you can zip it and attach it, preferably with the project files as well so those that have the same IDE can easily run it.

nucleon 114 Posting Pro in Training

The best solution is always the simplest one that does the trick. So, since you're only instantiating it with one type (i.e., a Comparable and it's derivatives), you don't need a template. That's what JohnA was saying.

class Comparable
{
public:
    virtual int compare( const Comparable& c ) const = 0;
};


class IsComparable : public Comparable
{
public:
    int compare( const Comparable& c ) const
    {
        return 0;
    }
};


class MyClass
{
private:
    const Comparable& myData;
public:
    MyClass( const Comparable& data ) : myData( data ) {}

    bool Contains( Comparable& c )
    {
        return myData.compare( c );
    }
};


int main()
{
    IsComparable isComp;
    MyClass myClass( isComp );
    // ...
}
nucleon 114 Posting Pro in Training

The whole point of prefix notation is to represent the formula in such a way as to eliminate the complications of precedence and association. To reinstate these complications is sidiotic.

I feel the most likely case here is that you are misunderstanding the assignment. It makes perfect sense to process exponentiation as right-associative; but it does not make sense to reinterpret prefix notation. So perhaps the input is supposed to be infix notation?

nucleon 114 Posting Pro in Training

main must return int (not void).
You are missing a closing brace.
"five" is a strange name.
datum is spelled with a u.
See comments in program.

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

struct five {
	float column1, column2;
};

// Does not need to be a friend of five since five's data are public.
istream& operator >> (istream& ins, five& r) {
	ins >> r.column1 >> r.column2;
	return ins;
}

int main(){

	ifstream input( "data.txt" );
	if ( !input )
	{
		cerr << "Cannot open file\n";
		exit( -1 );
	}

	vector<five> data;
	five datum;

	// If you test for eof, THEN read (and don't test again right
	// after) you will add an extra element to the end of the vector.
	// So test for eof something like this.
	while ( input >> datum )
	{
		data.push_back (datum);
	}

	// This loop displays the data.
	// You can be modify it to sum the data instead.
	for( size_t i = 0; i < data.size(); ++i )
	{
		cout << data[i].column1 << ", " << data[i].column2 << endl;
	}
}
nucleon 114 Posting Pro in Training

When Knuth talks about random numbers he mentions a CD of random numbers called "Black and White Noise" which is a mixture of deterministically sampled rap music combined with white noise.

nucleon 114 Posting Pro in Training

So you're saying that if you take the exact same exe and config file that works on your machine and transfer it to your friend's machine, it doesn't work?

Does he have the exact same OS as you? Has he installed your program in the same way as you have?

nucleon 114 Posting Pro in Training

> How would I set it as a Global variable

This question suggests that you may not be ready for WinAPI programming. You should master the programming language with console programs.

To make it global: First put HWND gHWndDlg; at the top of the program (say, just before the definition of keeprunning). Then under case WM_INITDIALOG: put the line gHWndDlg = hWndDlg; . Then in ThreadProc change all hWndDlg to gHWndDlg.

nucleon 114 Posting Pro in Training

ThreadTime does not have access to hWndDlg. You need to either make it global (DlgProc would set the global var in WM_INITDIALOG)or pass it as a parameter to ThreadTime.

nucleon 114 Posting Pro in Training

sid> Just check what would happened if delete would reset the pointer to zero:

Nothing would happen! Are you a mindless idiot? Did your brain fall out? Did you replace it with a turd you found on the ground? delete does nothing if it's passed a zero pointer! Moron!

I mean, how stupid would you have to be to think that the OP's question was about the designers of C++ being idiots? Answer: a complete and total moron, i.e., siddhantes!!! The OP's question was about the REASONING (something sid cannot comprehend) of the designers.

To the OP: Don't worry about the "sidiot," as we shall call him. He has serious personality problems. Just ignore anything he says. Everybody else does!

(P.S. The tone of the above is entirely contingent on the sidiot's original tone.)

MrSpigot commented: Ha! Got the tone just right! +1
nucleon 114 Posting Pro in Training

We need code tags and more explanation.

nucleon 114 Posting Pro in Training

Sounds good. :)

I forgot to mention above that if you do remove <afxres.h> (and use -1 instead of IDC_STATIC) you probably have to replace it with <windows.h>.

nucleon 114 Posting Pro in Training

The FONT line is about the 7th line in gui.rc. Put the MENU line after that.

In that same file you can get rid of <afxres.h> if you replace IDC_STATIC with its value, -1. I believe most people do this.

In main.c, <string> should be <string.h>. If you didn't get an error, then you're compiling in C++ mode (probably with a .cpp filename). This is not necessarily a problem, but if you mean to be using C, you should compile in C mode (with a .c filename).

nucleon 114 Posting Pro in Training

Write it to a string with sprintf (or wsprintf):

sprintf( buf, "Random Number: %d", random_integer );
MessageBox( 0, buf, ... )
nucleon 114 Posting Pro in Training

You haven't associated the menu with the dialog. Add this line after the FONT line in the dialog definition: MENU IDR_MAIN_MENU

nucleon 114 Posting Pro in Training

So you're saying that this piece of code will send a jpg file the first time it executes but not the second time or after that? What's the value of bytes_sent when the error occurs? If it is -1, what is the value of errno?

Notes:

You should open binary files with the "b" attribute since this makes a difference on some systems. At a minimum, your program will be more portable.

You may as well just return the same number in exit() for the different errors. If you actually meant these errors to be tested by another program, then you would give them all symbolic names and put that in a header for the other program to use. The most common return value seems to be -1 (all bits set in 2's complement).

sizeof(char) is always 1 by definition since sizeof returns its result in multiples of char, so you don't have to multiply by sizeof(char) when allocating space for chars.

nucleon 114 Posting Pro in Training

You may be able to figure it out with some detective work. Try running the old program and the new program in such a way that they should produce the same data. Then compare the files (viewing the binary file in a hex editor). But they could have added some things or moved some things so it could be difficult to compare them. If you happen to do the above (generate the "equivalent" text and binary files), and they're not too big, zip and attach them.

nucleon 114 Posting Pro in Training

So you basically want to write a program that will translate the new format binary file into the old format text file?
If it's a free program, can you get the source?
Or can you find a description of its binary format online?

nucleon 114 Posting Pro in Training

It's quite a challenge decoding a binary file with an unkown format! In general, it's not possible. How do you know if the first two bytes are the characters AB or the 16-bit integer with decimal value 1106 (assuming an ascii representation)? You might want to view the file in a hex/ascii viewer.

nucleon 114 Posting Pro in Training

You could try a different IDE/compiler.
MSVC++ defaults to unicode.

nucleon 114 Posting Pro in Training

No problem. :)

While I remember, you should change the test: b<MAX_KEYNAME_CHARLENGTH to b<MAX_KEYNAME_CHARLENGTH - 1 , otherwise you might overrun found_key.

And remember to test the return value of your function since it returns 0 when it fails (dereferencing this null pointer is what ultimately caused your crash).

nucleon 114 Posting Pro in Training

There WAS a problem in reading in the data. I don't know if I did it or you, but the extra strtok (to get rid of the letters A, B, C in the data) needs to be inside the loop. So change the code as follows:

if( strcmp( pch, "MESH_FACE" ) == 0)
		{
			int i, f;
			f = atoi( strtok( NULL, delim ));
			for( i = 0; i < 3; ++i )
			{
				strtok( NULL, delim );
				curObj->facets[f][i] = atoi( strtok ( NULL, delim ));
			}
		}
jephthah commented: man, you really slugged this one out. truly a herculean effort. +8
nucleon 114 Posting Pro in Training

That's how it looks to me too. If you rotate the pyramid it will actually disappear at one point. I don't know if that's a related problem or if that's how it always worked. Test out rotating the pyramid. If it's not working the way it used to then it must be something with the opengl part of the program and not the data structure since the pyramid is hard-coded.

P.S., I figured out what was wrong with passing fullFile to initScene. Basically, it needs its own copy of fullFile because strtok leaves the nulls in the string. I was under the mistaken impression that strtok would remove the previous null before it scanned to place the next one, so that when all was said and done the string would be back to its initial state. (Which is stupid because I recall writing a program a few years ago that depended on the nulls being left in.)

nucleon 114 Posting Pro in Training

Turns out the data structure was okay after all (it only crashed because I had forgotten to allocate space for the scene in my test program).

But I found the problem. It had to do with passing fullFile to initScene, you know that problem. For some reason it just doesn't work, and you tried to change it back (to reading the file a second time) but forgot a couple of things. I only change perhaps 2 lines.

So I think it's working. A table shows up now!

nucleon 114 Posting Pro in Training

MF: We've got bigger fish to fry! But that's definitely a good idea.

caged_fire: I've created a opengl-free version to just read and print the data structure and I'm getting errors with it! I probably won't be able to take a good look at it until tomorrow, though. I'll get back to you.

nucleon 114 Posting Pro in Training

That is strange. I finally got it to run just now. There's a black-and-white checkerboard "floor", a blue "sky", and a box and a pyramid floating in the sky.

nucleon 114 Posting Pro in Training

Oops! Remove the ampersand from that one. So it should be: glVertex3fv(object->vertices[facet[i]]); Also, you might want to use atoi instead of atof in the line given below since you're reading an integer (the line is in loadScene): curObj->facets[f][i] = atof( strtok ( NULL, delim )); Let me know if it displays the scene or not.

nucleon 114 Posting Pro in Training

Try this. ;) But it's the essentially the same. Attach your project.c file if it's still not working.

void drawPolygon( Object *object, int iFacet )
{
	int i;
	int *facet = object->facets[iFacet];

	glBegin( GL_POLYGON );
	glColor3ub( 128, 64, 0 );

	for( i = 0; i < 3; ++i )
		glVertex3fv(&object->vertices[facet[i]]);

	glEnd();
}
nucleon 114 Posting Pro in Training

You define a buffer called found_key to hold each key as it is read. It has a length of MAX_KEYNAME_CHARLENGTH (defined, suspiciously, as 20).

If you are sure your keys will never be more than 19 characters long (leaving space for a terminating null), then this is okay, except for one thing: you are also reading values into this same variable as if they were keys! You need to skip the value of keys your not interested in so that you don't read them into found_key and possibly overrunning the buffer or even misinterpretting the value as a key.

Basically you'll have to skip values in exactly the way you do when you want to read them, except you won't be storing them.

nucleon 114 Posting Pro in Training

Instead of setting pid and ppid, don't you just want to print them? You cannot return them to the parent (well, you can, but it does not seem to be necessary in this assignment).

And your code is missing an end brace.

nucleon 114 Posting Pro in Training

I believe this works.

void drawPolygon( Object *object, int iFacet )
{
	int i;
	int *facet = &object->facets[iFacet][0];

	glBegin( GL_POLYGON );
	glColor3ub( 128, 64, 0 );

	for( i = 0; i < 3; ++i )
		glVertex3fv(&object->vertices[facet[i]]);

	glEnd();
}
nucleon 114 Posting Pro in Training

Try this (yet another ampersand): glVertex3fv(&object->vertices[facet[i]]);

nucleon 114 Posting Pro in Training

Mostly it was missing ampersands (to take addresses instead of values). And I forgot to return the size from initScene. Try it now.

nucleon 114 Posting Pro in Training

I would've run it if I had any data! Actually, I just made some up and got it to run, but I'm not sure how to make it crash. Could you post a single-file (minimal), runnable (crashable, actually!) example with hardcoded data that makes the program crash?

nucleon 114 Posting Pro in Training

Yes, that's the right thing to do there. And I forgot to change the call to "shape" in display to a call to drawScene.

nucleon 114 Posting Pro in Training

tux> If your computer has more than a GB of RAM that wouldn't be a problem

But the OPs computer crashed with just a megabyte-sized array. :( So it's not about total space available, but about how much stack space is reserved (which of course can be increased with a compiler option).

nucleon 114 Posting Pro in Training

WH: What are your system specs and compiler?

nucleon 114 Posting Pro in Training

The obvious thing wrong with your program is this line: pid = (int)getpid(); int ppid = (int)getppid(); You are defining another variable called ppid, shadowing the other one. You want to remove "int" before ppid.

nucleon 114 Posting Pro in Training

WH: You're saying that the code below does not crash on your system?

#include <iostream>
int main() {
    int matrix[512][512][512];
    matrix[0][0][0] = 1;
    std::cout << matrix[0][0][0] << '\n';
}

Assuming 32-bit ints, that's half a gigabyte! Removing the 3rd dimension works for me, but that's only a megabyte.

nucleon 114 Posting Pro in Training

It would be easier if I could run this thing, but I'm getting linker errors and cannot (easily) resolve them. Anyway, here's a rewrite of the data structure to enable loading mutiple scene files into a scene array. I've renamed a couple of functions, etc., as well. See if it runs and look through it carefully to understand the changes. Overall, it's simpler than before.

nucleon 114 Posting Pro in Training

The problem seems to be that you're incrementing i all over the place but only testing if it exceeds (or equals) buf_length at the top of the loop indexed by i.

There is also one possibility of an access before the beginning of the array, so I added a check for that.

I added parens to a condition.
You had: cond1 && cond2 || cond3 but meant: cond1 && (cond2 || cond3) I added an assert at a critical place, but you will need more tests to ensure that i does not go out-of-range. The rest is up to you.

const char * sf_extract_key( const char * buf, const char * find_this )
{
	int x, b, found_value_length, buf_length = 0;
	char found_key[MAX_KEYNAME_CHARLENGTH];
	char delim;
	char* found_value;

//!	while ( buf[buf_length] != '\0' ) buf_length++;
	buf_length = strlen( buf ); //! same thing!

	for ( int i=0; i < buf_length; i++ )
	{
		//! Added test to protect against buf[i-1] looking before buf[0]
		if ( buf[i] == '"' && (i == 0 || buf[i-1] != '\\'))
		{
			i++; // move past starting "

			//! Added parens around the or clause
			for ( b=0;
				  b<MAX_KEYNAME_CHARLENGTH &&
				  (buf[b+i] != '"' || buf[(b+i)-1] == '\\');
				  b++ )
				found_key[b] = buf[b+i];
			found_key[b] = '\0';

			if ( strcmp(find_this, found_key) == 0 )
			{

				i=b+i+1; // move past ending "

				//! This is just a debugging aid.
				assert(i < buf_length - 1);

				if ( buf[i] == ':' && buf[i+1] != '{' && …