nucleon 114 Posting Pro in Training

Your program has too many errors to enumerate. You need to learn the basics (like you can't say Public instead of public; capitalization counts). Get a decent book and work through the examples.

nucleon 114 Posting Pro in Training

>You normally don't need the ignore( ) between two input
>statements of the same type.

Or when the getline() is before the cin>>.

hurbano commented: thanks for the help +1
nucleon 114 Posting Pro in Training

You do realize that you cannot use spaces. You must use tabs.

nucleon 114 Posting Pro in Training

"Please criticize my code." My favorite question! :)

The biggest problem is that your variable names are too long. "Descriptive" does not mean "long". Here are some better names:

mathematicalOperation   expr       (or expression, if you must)
operatorSign            oper       (or operation)
getFirstDigitIndex      iDigit
operatorSignIndex       iSign
firstNumber             strNum1    notice that these go nicely
secondNumber            strNum2    with the names num1 and num2

Here are the structural changes I would make:

int main() {
    string expr;
    float num1, num2;
    char oper;
    while (1) {
        cout << "Enter an expression (-1 to exit)\n";
        cin >> expr;
        if (expr == "-1") break;
        int iDigit = ...;
        int iSign = ...;
        if (iSign == -1) {
            cout << "No operator found.\n";
            continue;
        }
        // etc.
    }
}

Get rid of the "SEE YOU LATER" at the end. (Why do beginners always do that?)

Do not put copyright notices in simple code like this (or anything you write for the next four years).

tux4life commented: Nice advices to the OP ! :) +1
nucleon 114 Posting Pro in Training

Your dream of

char string[15];
string = getstring(15);

will not work.

You either have to do this (and why not?)

getstring (string,15);

Or this

char *string;
string = getstring(); // getstring allocates string storage
// use string
free (string);
nucleon 114 Posting Pro in Training

> there are no points for creativity in programing

And how would you know? You don't seem to have much experience! :)

In fact, creativity is the only thing that gets points in programming. If it wasn't for the creativity and artistry involved, I wouldn't bother doing it. (Who would?)

And better names mean better programs. It has been said that good naming is one of the most difficult things to learn, and naming is certainly one of the worst parts of beginner programs (along with structure, a related problem).

In your case, I would rename your people struct to be People (with an uppercase P) and then call the vectors people (with a lowercase p).

Other points on your program:
* don't append to the file in write_out (overwrite the file instead)
* in read_in you need to check for eof after the first getline
* in struct address, declare numbers and zip as strings (they're not really integers since, for example, there's no sense in adding them)

nucleon 114 Posting Pro in Training

The "download" link somehow added backslashes before every single and double-quote.

I notice that you have no increment of the iterator in write_out. Add a ++itr before the end-brace of the while-loop.

If that doesn't fix the problem, can you be more specific? How would we recreate the problem?

[edit]
Now that I've actually run your code, I notice that you need to pass the vector by reference to add and del. So change their declarations like this:

void add(vector<people>& thing)
// ...
void del(vector<people>& thing)

You can probably think of a better name than "thing"!
[/edit]

nucleon 114 Posting Pro in Training

It is my understanding that the third pointer level was there to make an array of objects. But since an Object3D object represents a single object, you would make a pointer to an array of them like this: Object3D *object; The asterisk above now represents the level of indirection previously represented by an (extra) asterisk in front of each of the variables facets, vertices, nFacets, and nVertices in Object3D.

nucleon 114 Posting Pro in Training

Let's see. There are 24 places that the pieces could be. There are 15 identical pieces for each player, and only one player's pieces can be in a particular position.

The simplest data structure that fits these requirements is an array of 24 integers. Zero means the space is empty. Positive values indicate black (say) while negative values indiate white. The absolute value indicates how many pieces are in that position.

nucleon 114 Posting Pro in Training

It would not compile until I made the following change:
In StudentGrade.h, in the StudentGrade class, change the declaration of operator<< to this (making StudentGrade const): friend ostream& operator<< (ostream &out, const StudentGrade &right); And of course change the definition of operator<< in the code to match.

nucleon 114 Posting Pro in Training

I don't know wxWidgets, so I'm just guessing here. Try making DECLARE_EVENT_TABLE(); public instead of private.

If that doesn't work, try putting this in your code:

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
END_EVENT_TABLE()

Or, if you aren't goint to have any events, remove DECLARE_EVENT_TABLE(); altogether.

nucleon 114 Posting Pro in Training

Presumably something needs to be declared as virtual in Utility. Without code, it's hard to say exactly what.

nucleon 114 Posting Pro in Training

You're pathetic.

nucleon 114 Posting Pro in Training

Calm down, jephthah.

I am well aware of the problems with globals. I simply assumed that his project was due soon, and looking at the crazy structure of the whole thing it would not be worth his time in this particular instance to "de-globalize" his variables.

Have you even read the code? For instance, how would he pass the requisite data to display()? I assume there's a solution, but I don't feel like working it out. Are you trying to help anybody but yourself here?

What exactly is your problem?

nucleon 114 Posting Pro in Training

And you're using double-quotes for character constants. You should be using single-quotes.

nucleon 114 Posting Pro in Training

The full-cookie solution would be to use conditional compilation to implement code for each platform. Here is an MSDN page describing the functions in conio.h. Remember that you can simply open these headers up and look at them to see what's in them.

jephthah commented: yeah, that's it. +5
nucleon 114 Posting Pro in Training

You need to declare your object array like this:

typedef struct Object3D {
	int**   facets;
	float** vertices;
	int     nFacets;
	int     nVertices;
} Object3D;

Object3D *object; // Object array
int numObjects;   // Number of objects in object array

And the object array is accessed like this: object[nObj].nFacets At this stage I wouldn't bother de-globalizing your variables; your code-structure (such as it is) depends on them being global.

nucleon 114 Posting Pro in Training

conio.h (if available to you) has the function _getch() which is unbuffered and does not echo the character read.

nucleon 114 Posting Pro in Training

You're trying to pass a const object to a function that does not receive a const object. Change one or the other.

nucleon 114 Posting Pro in Training

Someone might actually look at your code if you post it as a single zip file. Edit your previous post if possible.

nucleon 114 Posting Pro in Training

asin() in <cmath>
Try here for a description.

nucleon 114 Posting Pro in Training

You need to initialize filledCount to zero (or get rid of it and just use i).

Try putting the cin.ignore() before cin >> choice

nucleon 114 Posting Pro in Training

You don't need to do this: planner[x][2].ClassMeet Just this: planner[x].ClassMeet And planner should not be defined like this: classPlanner planner[100][6]; but like this: classPlanner planner[100]; Also, Print and Enter don't return anything, so make them void. Get rid of the global x variable, define it in main, and change Enter to accept a reference as well as change Print and Enter to accept a classPlanner array.

Also, if the class number is in fact equal to x, then don't ask for the class number (and get rid of the entry in the structure). Just store the other information at position x in the array, like you are doing.

So here's a skeleton:

void Print (classPlanner planner[], int x) {
}

void Enter (classPlanner planner[], int & x) {
}

int main() {
    classPlanner planner[100];
    int x = 0;
    //...
    Enter (planner, x);
    //...
    Print (planner, x);
    //...
}
nucleon 114 Posting Pro in Training

You're looking for something like this:

struct Class {
    string name;
    int    num;
    Day    meet;  // For Day use whatever is appropriate
    Time   start; // Ditto for Time
    Time   end;
    string teacher;
    int n  umStudents;
};

cin >> planner[x].name;
cin >> planner[x].num;

As for making the array index equal to the class number, that depends on how the classes are numbered. You don't want a bunch of missing elements in the array wasting space.

nucleon 114 Posting Pro in Training

Is it because you're calling start() at the beginning of getNext() ? According to your comment for start() it moves the pointer to the beginning of the list.

nucleon 114 Posting Pro in Training

Filter the output with grep: ./Test "$i.txt" "$i.obj" | grep -vi '^[:alpha:]' Perl's good for this:

for $i (1..5) {
  for (`./Test $i.txt $i.obj`) {
    next if /^\s*\w/;
    print;
  }
}
nucleon 114 Posting Pro in Training

Here's a piece of a program I wrote to play with PCM wave files. It displays the header information. Run it on both of your files and post the results back here. The filename is hardcoded in the first line of main. Uncomment the last line if you need to pause the console.

nucleon 114 Posting Pro in Training

Have you looked at RegisterHotKey ?

nucleon 114 Posting Pro in Training

That is a contradiction. windows.h provides the functionality of the windows platform. You're probably thinking of some piece of that functionality, such as might be provided by OpenGL etc.

nucleon 114 Posting Pro in Training

What is the format of the wave files? Is it PCM or are they compressed?

nucleon 114 Posting Pro in Training

> do you have a career in programming?

No, I'm just a hobby programmer, but I've been programming since the age of 8 or 9 and am 25 now and have read quite a few university texts (algorithms, operating systems, AI) as well as Knuth. My job is VERY different but I love it! You probably make more money as a programmer, though.

nucleon 114 Posting Pro in Training

Unfortunately I cannot run your code right now, but in looking it over I noted the following.

The strangest thing (if I'm not mistaken) is the loop in polygon. Shouldn't you be passing in "i" from shape? I may just not understand what's going on here, but it seems weird to be looping through numObjects (in polygon) within a loop that is doing the same thing (in shape).

In readFile, since you're treating the whole file as a string, you should null-terminate it. So malloc an extra char's worth and be sure to set it to zero. (Or use calloc.)

The following are points that probably won't change anything but are still good practice.

You should really move the fopen() call into readFile and pass in the fileName. There's no advantage to doing it the way you're doing it. Also, you should probably read the file in text mode instead of binary mode. (Change "rb" to "r".)

In loadShape, since you've already read the entire file into fullFile before calling countObjects, you may as well pass fullFile to countObjects so it doesn't have to read the file again.

Your delimiters are better expressed like this: char * delim = " *:\t\n\r\\"; You should compare the result of strcmp to 0 (not NULL).

nucleon 114 Posting Pro in Training

You're gonna kick yourself! Instead of this for(i = 1; text_tokenized[i] != NULL; i++) You mean this: for(i = 1; i < words; i++) {

nucleon 114 Posting Pro in Training

The more the merrier!
I wonder why it has that parameter, though.
Seems kind of pointless.

nucleon 114 Posting Pro in Training

It seems fairly self-explanatory. Remember to (of course) look the functions up on MSDN. Just include windows.h to use the code above.

If you must use ShellExecute (and there certainly can be reasons for that) then use ShellExecuteEx since it gives you the process handle.

nucleon 114 Posting Pro in Training

Assuming Windows, here's an example of waiting for an exe to finish.

STARTUPINFO si = {sizeof (STARTUPINFO)};
    PROCESS_INFORMATION pi;
    CreateProcess( "\\windows\\notepad.exe", NULL,
        0, 0, 0, 0, 0, 0, &si, &pi );
    WaitForSingleObject( pi.hProcess, INFINITE );
nucleon 114 Posting Pro in Training

Nice one, NicAx64 !!!

nucleon 114 Posting Pro in Training

time's parameter is an alternate return path. If you pass in NULL (or 0) it is ignored. Otherwise, you must pass the address of a time_t object which will be filled with the time.

vmanes commented: Good clear answer! +8
nucleon 114 Posting Pro in Training

Post your entire program again and I'll take a look at it.

nucleon 114 Posting Pro in Training

It's a good try, but I don't think it'll work!

nucleon 114 Posting Pro in Training

That idea still won't work. I was thinking of something like the code below. Unfortunately, I can't see how you can template the return values since the parent class (which defines the virtual function) cannot be templated; otherwise it will not be the same type for each child, since parent<int> is a different type from parent<double>.

#include <iostream>
#include <vector>
#include <string>

class parent{
public:
  virtual void show() = 0;
};

template<typename T>
class child : public parent {
public:
  child(T m) : member(m) { }
  void show(){ std::cout << member << '\n'; }
private:
  T member;
};

typedef std::vector<parent*> Vec;
typedef Vec::iterator VecI;

int main() {
    Vec v;
    v.push_back(new child<int>(123));
    v.push_back(new child<double>(1.23));
    v.push_back(new child<std::string>("howdy"));
    for (VecI i = v.begin(); i != v.end(); ++i)
        (*i)->show();
std::cin.get();
}
nucleon 114 Posting Pro in Training

Is dwExtraInfo always 0? If not, try interpreting it as the keystate. That is, test it against, say, MK_CONTROL while pressing the control key. If it's just an arbitrary number, then maybe it's pointing to something ... but what? The lack of documentation on this is pitiful.

I've asked on comp.os.ms-windows.programmer.win32. I know I should have told YOU to ask, but I just did it. ;) I will post any answer back here.

nucleon 114 Posting Pro in Training

You're right. I wasn't thinking clearly with that last piece of sh..., I mean code.

Since you do not seem to need the previous data, you may as well just free the memory and allocate it again with your allocate_memory function. So just free it like this before allocating it again.

void release_memoryi(GLint*** facets, int nShapes, int nRows) {
    int i, j;
    for(i = 0; i < nShapes; ++i) {
        for(j = 0; j < nRows; ++j) free(facets[i][j]);
        free(facets[i]);
    }
    free(facets);
}
nucleon 114 Posting Pro in Training

It doesn't always return zero. (Try 4, 5, 6.) But you should probably make at least s a double, and probably also a, b, and c.

nucleon 114 Posting Pro in Training

It's because of integer division.
For two floats, 1.0 / 2.0 is 0.5.
For two ints, 1 / 2 is 0, thowing the fractional part away (and no rounding).
Actaully, you can leave n and x as int's if you cast at least one of the division operands to a float:

for ( n = 2; n <= 1000; n += 2 )
    {
        Answer = Answer * ( (float)(n*n) / ( x * (x + 2) ) );
        x += 2;
    }
nucleon 114 Posting Pro in Training

n and x need to be floats (or better yet make everything doubles).

nucleon 114 Posting Pro in Training

> that's exactly what I want to avoid
That's what I figured. ;)

As for your second question, it does not seem possible. The point here is that wrapper is not a type. Only wrapper<int>, etc. are types. So you cannot have a vector<wrapper>. You can do something similar with a common base class and virtual functions, but you probably know that.

nucleon 114 Posting Pro in Training

It would seem that your only hope (besides the static idea) is to investigage what MOUSEHOOKSTRUCT's dwExtraInfo member holds.

nucleon 114 Posting Pro in Training

You need to set y to 1 at the top of the loop so it's initialized every iteration. Your do{}while() condition should be x > 0 since you want to multiply every digit together here. The outer while() condition should still be x > 9.

nucleon 114 Posting Pro in Training

I only looked at allocate_memoryi and reallocate_memoryi. Any problems with them probably also exist in the "f" models. Compare the code below with the original carefully to see the differences.

GLint ***allocate_memoryi(int nShapes, int nRows, int nCols)
{
	GLint ***shapeArray;
	shapeArray = (GLint***) malloc(nShapes * sizeof(GLint**));
	for(i=0; i<nShapes; ++i)
	{
		shapeArray[i] = (GLint**) malloc(nRows * sizeof(GLint*));
		for(j=0; j<nRows; ++j)
		{
			shapeArray[i][j] = (GLint*) malloc(nCols * sizeof(GLint));
		}
	}
	return shapeArray;
}

GLint ***reallocate_memoryi(int nShapes, int nRows, int nCols)
{
	GLint ***shapeArray;
	shapeArray = (GLint***) realloc(facets, nShapes * sizeof(GLint**));
	for(i=0; i<nShapes; ++i)
	{
		shapeArray[i] = (GLint**) realloc(shapeArray[i], nRows * sizeof(GLint*));
		for(j=0; j<nRows[i]; ++j)
		{
			shapeArray[i][j] = (GLint*) realloc(shapeArray[i][j], nCols * sizeof(GLint));
		}
	}
	return shapeArray;
}

Also, you really shouldn't be using all those globals. It's just lazy, and as your program gets bigger it will come back to haunt you.