raptr_dflo 48 Posting Pro

That's a lot of code! What platform are you building on? I'd be happy to help dig through it, if I can match your development environment.

Also, any particular reason you've implemented most/all of your methods in models.h instead of a separate models.cpp file? Have you tried running in a debugger and/or adding debug printf/cout statements throughout your code, to track how far it's getting before you hit the SIGSEGV?

Since you only do a GL.Init(), build and draw a glModel instance, and then call GL.Update() and check GL.window.key, can you make copies of your code with everything you -don't- need stripped out (or effectively disabled by surrounding unused blocks with #if 0 and #endif pairs), and see if the problem persists?

raptr_dflo 48 Posting Pro

I have no idea why this question is in a C++ forum, unless you want to do this programmatically for some reason. For simplicity, I'd recommend using the relatively common 'zip' tools to zip the contents of the "Client" folder into archive "Client.zip" and then rename the file to "Client.any" to make it appear unusable to the casual observer. There are other techniques which can further obfuscate or even encrypt the content, so that the file is unusable even if renamed back to "Client.zip" unless the end-user knows how to unobfuscate/decrypt the content first.

raptr_dflo 48 Posting Pro

c hickam,
Please start new threads for cases like this, rather than tacking onto a thread started over 6 years ago, and untouched for almost 18 months.

raptr_dflo 48 Posting Pro

Good catch, NathanOliver, thanks!

raptr_dflo 48 Posting Pro

Both the codes are there for you to see.
The digitalWrite() function is suppose to behave the way it normally does.

What does it normally do? I'm not an Arduino developer, that's why I asked. This is a general purpose C++ programming forum, and I don't see any obvious problems in the C++ code you've presented.

The problem is that I want the LED to stay HIGH as long as G1 is executed. And stay LOW as long as G28 is executed.

I understand, but I don't see any indication that the code you're executing would call the wrong function or indicate that the LED should -not- stay HIGH or LOW as you've specified.

The commands take some time, right !
If I send
G1 X10 Y10
it will take some time to move.

Not being an Arduino developer, I don't know what X10 or Y10 should do, or what "movement" is expected from your system.

I want the LED to stay ON as long as it is moving and after the completion of one command, just keep on looking for what is coming, G1 or G28, and turn HIGH or LOW as defined.

Right. And it looks like that's what your code is doing, so I'm at a loss. With any luck, somebody with some similar application-specific experience will notice this thread and contribute some insight.

raptr_dflo 48 Posting Pro

skiboy209,

Try consistently indenting your code. It will help you and others more clearly see what is going on. I think your errors involve where you start the nested loop (the second "do {" line), and where you ask if you want to do it again and end the nested loop, but I'm not positive. Try a couple of things, and then re-post the current state of your code if you're still stuck.

raptr_dflo 48 Posting Pro

Hmmm, while I couldn't reproduce it, I wonder if the problem is the lack of a space between "#include" and "<iostream>" -- it sounds like it's ignoring the # and trying to do something template-like.

BTW, which version of gcc are you using? gcc --version . I have a relatively old "g++.exe (GCC) 3.4.5 (mingw-vista special r3)" because of some of the libraries I need to link against. :)

raptr_dflo 48 Posting Pro

For what it's worth, the solutions here are implementations of a DepthFirstSearch algorithm, which maps well onto recursion:

(approximately valid but untested)

int KeepMoving (int [][DIM] board, int start_x, int start_y)
{
    if (NoPossibleMoves(board, start_x, start_y))
        return 0;
    int max_moves = 0;
    for (int k=0; k<=7; k++) {
        int next_x = start_x + horizontal[k];
        int next_y = start_y + vertical[k];
        if (IsValidMove(board, next_x, next_y)) {
            int moves = KeepMoving(board, next_x, next_y);
            if (moves > max_moves)
                max_moves = moves;
        }
    }
    return 1 + max_moves;
}
raptr_dflo 48 Posting Pro

And if you want the number of elements in the array to be returned, then

void InputStudents(studType Students[], int maxStudents, int& NrE)
...

Note the addition of the '&' after int, meaning that a reference to NrE is what's passed. Also, I've included the size of the array, rather than hard-coding a value of 10 inside the function ... then call it as

studType the_students[100];
int num_students = 0;  // the number of valid students in the array so far
InputStudents(the_students, 100, num_students);
// on return, num_students will contain the number of valid students in the array

Also, why are you writing new registered students to outfeil/outfile (regardless of how you spell it) as you read them in from the user? This will make deleting them much harder!

As far as why it's empty when you re-run the program, the default usage of ofstream::open() is to delete any existing content. If you want to append new content onto the end, use outfeil.open(student_records.txt", ios_base::app); . Or possibly ios_base::out|ios_base:app if just app doesn't work. See http://www.cplusplus.com/reference/iostream/ofstream/open/ for more details.

raptr_dflo 48 Posting Pro

Since you marked this thread solved, I imagine that means you figured out you don't need to prepend member names with the classname at, e.g., line 7 of your .cpp file. :)

raptr_dflo 48 Posting Pro

Well, you need to reset i to 0 before line 12. Your code will be easier to read if you create a few simple (and well-named) functions that do specific things like:

bool isPrime(int num)
{
    bool is_prime = True
    // loop to determine if num is a prime
    // if NOT prime, set is_prime = False

    return is_prime;
}

You definitely aren't checking your array-bounds ... you're limiting 'a' to contain up to 100 primes, but because you don't reset 'i' then you're writing past that point in the array at line 26.

Once you fix that, you have a logic problem at line 24, so if you specify a sufficiently-large user_num, you'll still have problems....

And ultimately, you need to check the value of 'i' and print an error msg to the user if you've already found 100 primes and aren't all the way up to user_num yet.

raptr_dflo 48 Posting Pro

Since it appears that your Grid2D is a template class that you then specify by telling it what to use internally, it should be sufficient to declare the actual struct-type you need for each specific grid:

struct fluidProperties1 {
  float foo;
  float bar;
};

struct fluidProperties2 {
  float foo;
};

struct fluidProperties3 {
  float bar;
  float baz;
};

Grid2D<fluidProperties1> grid1;
Grid2D<fluidProperties2> grid2;
Grid2D<fluidProperties2> grid3;

If this isn't what you had in mind, please clarify your use case a bit more.

raptr_dflo 48 Posting Pro

Since the functions and objects defined in .dlls can be used directly in a C++ program simply by linking against them, e.g. g++ myobj.o -o myprog -lole32 (or just adding the OLE library to your VS project), the notation in C++ should be much simpler. I have no actual experience doing this, I'm afraid, but found a sample C/C++ snippet here: http://www.relisoft.com/win32/olerant.html -- hope that gets you going!

raptr_dflo 48 Posting Pro

It sounds like your issues are related more to the Arduino interface than to C++ programming. How is the digitalWrite() function supposed to behave? Is it supposed to maintain the state that you specify (LOW or HIGH)? Or is it supposed to trigger a transient switch to that state and then back to whatever it was before? Or if digitalWrite() is a function you have implemented, maybe the problem is there.

raptr_dflo 48 Posting Pro

Your infile >> name >> midterm...etc won't work because you haven't declared a struct.

Declaring a struct has nothing to do with the problem.

Instead, you've declared arrays that can hold 50 names, but only 5 of everything else. Then your Read_Data() function tries to read 10 entries into those arrays. Also, you shouldn't specify the length of the names[] array at line 51, since you don't need to specify the length of any of the others.

Finally, since you loop over input lines to fill your arrays, you need to loop over your arrays to write output lines! Replace line 46 with a call to a Write_Data() function, which should look similar to your Read_Data() function (except passing an ofstream& as the first parameter, and changing the >>'s to <<'s, and possibly adding "<< endl").

raptr_dflo 48 Posting Pro

And once your last node's Next pointer points back to Head, you have to maintain and deal with that.

As far as dealing with it, your print_circle() routine will never end as currently written (current will never become NULL).

As far as maintaining it, you need to address specific cases:
+ what should happen when you add the first node to an empty list?
+ what should happen when a new node is added to the front of the list?
+ what should happen when a new node is added to the end of the list?
+ (as long as the last node already points to Head, adding a new node in the middle of the list should work as currently implemented!)

raptr_dflo 48 Posting Pro

Your code in check_num() is fine (other than not maintaining leading zeroes, as Ketsuekiame pointed out). Instead you have a subtle error on line 71. Can you spot it yourself?

While it doesn't matter, since you're not changing a, b or c within check_num(), you don't need to recover the values back in the caller. Therefore you don't need to pass them by reference, and line 48 can be int member :: check_num(int a,int b,int c) .

raptr_dflo 48 Posting Pro

Several problems:

You declare variables like ROWS, COLS, ALPH and VIG internally to your Table() method, so they are not accessible out side of it. Fix this by making them members of your Vigenere class, and then either:
+ pass 'alphabet' into your Vigenere::Vigenere() constructor and initialize them there, or
+ leave them uninitialized until you call your Table() method

Your EraseChar() method doesn't erase non-Italian letters out of the A-Z range. While it's probably slower, consider comparing each character in the input str against each character in ALPH.

Use the same EraseChar() method on key, in your constructor at line 8 above. The code in the constructor is almost the same as in EraseChar(), but is broken since you don't decrement i when you remove a character.

At line 14, it looks like you're trying to re-extend your key to be the same length as your text, but you don't have a text variable at that point, you're trying to append characters from the key that don't yet exist in it (when cnt is > key.length()) onto the end of it, and the test for lengths-not-equal is redundant (checking less-than is sufficient).

Let's get that much fixed and then see what problems remain.

raptr_dflo 48 Posting Pro

You are correct, you are not handling the file-management aspect correctly, I've told you exactly why your logic (currently in lines 72-100) is flawed, and how to reorganize it so that it does what you expect. I'm not going to tell you again, please read what I've already written previously in this thread. If there's something in there you don't understand, feel free to ask, but don't post the same code over and over and ask us to help you.

raptr_dflo 48 Posting Pro

int arr[13][17][19];
arr[3][11][7]=7;
//can be replaced with
int*arr=(int*)malloc(13*17*19*sizeof(int))
arr[ 3*17 + 11*19 + 7 ]=7;

Hmmm, I think that indexing scheme should read:

arr[ 3*17*19 + 11*19 + 7 ] = 7;

Another advantage is that if you're frequently moving to an adjacent element, you can do things like:

int updown_offset = 17*19;
int northsouth_offset = 19;
int eastwest_offset = 1;

int *ptr = &arr[ 0*17*19 + 11*19 + 7 ];  // or whatever starting position
for (int updown=0; updown<13; updown++) {
    *ptr = 7;
    ptr += updown_offset;
}

Not really as readable as arr[k][11][7] = 7; , but the latter would require 3 adds and 3 pointer dereferences for each time through the loop, instead of 1 add and 1 dereference (and of course an add and a compare for the loop variable either way). It starts to matter when you're doing heavy math across every element in your multi-dimensional array!

raptr_dflo 48 Posting Pro

std::vectors aren't strictly needed, but they do take care of the dynamic memory allocation for you, and tend to do so in a reasonably efficient manner.

I'm curious though about what your application is, that it requires several large 2-dimensional arrays, and whether it would be worthwhile or appropriate to use a struct (or class, since this is the C++ development forum):

// instead of
int slf[4096][16]={0},slr[4096]={0},rh=0,crs[4096]={0},cri=0,moo=0,nb=0;
int qlf[4096][16]={0},wlf[4096][16]={0},kd=0;

// use the following
struct Datapoint {
    int slf[16], slr, crs;
    int qlf[16], wlf[16];
};
Datapoint p[4096];
int rh=0, cri=0, moo=0, nb=0;
int kd=0;

if, in fact, all of those variables (or more) are related in a way that it makes sense to group them.

... i always find out that one of the counters for the array has gone way off the limit, like ith[4096][16] will have values uptil ith[6400(counter)][16].

This has to do with the order in which you declare your arrays (that there is additional space after "ith" allocated for other arrays, so you can still index into that space), but why are you looking at ith[6400][16] if you only declared it up to [4096][16]? If there weren't other variables declared, you probably would have incurred a stack error and/or segment violation for trying to look into memory that didn't belong to your process.

raptr_dflo 48 Posting Pro

You are still not using [ CODE ] tags.

Then, read out loud what your program is doing:
for each name in input.txt you do:
+ read the name, read the start integer, read the end integer
+ for each integer in the range you do:
+ + read a line from input1.txt
+ + append the name to the line if the integer matches
+ + write out the line
+ + (do not reset the input-stream for input1.txt -> the remaining integers do nothing because pch.eof() is always true after the first integer)

You have several logic flaws. First, you are writing out the line from input1.txt whether or not the match succeeded and name was appended. Second, you are not appending the name onto the line for all possible matched integers before outputting. Third, if your $POINT ID aren't sorted correctly, you could end up with interleaved names in the correct output, but your looping strategy won't handle that.

You're off to a good start by reading input.txt into structures, but do that in a separate loop first, before you look at input1.txt.

Then re-read what I wrote previously. Your outer loop should be over lines in input1.txt: for each line, you need to determine which point ID is specified (if any), and if there is one, which name has an ID range containing that ID value (if any), and if there is matching name, append …

raptr_dflo 48 Posting Pro

Does the following work for you?

int main()
{
    PlaySound("RFD",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);
    Sleep(10000);
    PlaySound(NULL, NULL, 0);
    return 0;
}

In the future, please try to find a minimum failing case, or feel free to trim out code that you're sure doesn't contribute to the problem. But thanks for using CODE tags!!! :)

raptr_dflo 48 Posting Pro

I took a quick look, and as far as I can tell, your program can't get past line 33 because the only way out of your while loop is via system("exit") (which I didn't even think about until just now, and appears to kill off the CommandPrompt that your program is apparently running in. Probably not really the best approach, and besides there's still no way to set the your firsttime string to "not".

As far as not writing anything into the file, it may be your strategy for terminating the program is brute-force killing it off before it has a chance to flush output buffers to the disk. Try something simple like "return 1;" for an error condition or "return 0;" for success, instead of "system("exit");"

raptr_dflo 48 Posting Pro

It sounds like you're looking for basic systems engineering understanding. This is a C++ programming forum. Various people here can point you in the right direction for certain kinds of programming questions, but it sounds like you're entirely out of your league as far as the requirements of your project, and no amount of tips or pointers here is going to fix that.

As far as developing an activity diagram from your use-case diagram, first take a look at http://www.agilemodeling.com/artifacts/activityDiagram.htm . Then if you have specific questions about your use case, it would be helpful if you provided a link to the use case diagram.

raptr_dflo 48 Posting Pro

You don't generally "change" the command-line arguments. You either specify them or not, as needed and as dictated by the program. If you're running your program by double-clicking on a desktop icon, you don't have a command-line, so you don't get to specify any arguments. But more modern user-interactions methods, such as dragging a text-file-icon onto an editor-application-icon to run the editor program with the text-file pre-loaded for editing is a fancy version of specifying the (optional) text-file path on the command-line when starting the editor.

As far as which to use (assuming you're running from a command-line, such as the "Command Prompt" in Windows or a shell in cygwin or an equivalent terminal window on Mac, Linux, etc.), both have their uses.

In addition to specifying start-up environment/state for a program, a config-file can be made read/write and can store user preferences made while the program is running -- this is more-or-less how all the various apps' info gets saved in the iPhone's "Settings" tool. While the underlying implementation details may differ, you can think of it as reading and writing a config file for each installed app, and then the app also reads its config file on start-up.

The command-line is better suited for information specific to that specific run of the program, but can also be used to override configuration values on an as-needed basis -- faster than editing the config-file and then changing it back later.

As far as the specific arguments …

raptr_dflo 48 Posting Pro

For starters, for the first value of j, you go all the way through the file, replacing occurrences, but then don't save the file or re-initialize pch.

Instead, it may be more efficient (depending on the number of values of j) to read each line from the file, then loop over j, replacing each occurrence of each number in turn, and write the line out to a new file. Then move on to the next line of the input file.

Also note that you will get unexpected results if x is 2 and y is 30 (for example). I leave it to you to understand what those results will be, and how to fix the code accordingly, though for your use cases it might not come up.

Finally, please, please, please (and this goes for everyone!) surround your source code with CODE blocks! Simply select it all with the mouse, and click the [ CODE ] icon at the top of the editor. Does nobody read the clearly-titled "Read this before posting" thread? :-/

raptr_dflo 48 Posting Pro

but then does that mean for the level 2 clips i would have to declare another SDL_Rect in the class? and for the rest of the levels the same?

I'm not sure. The code you've posted in your Google Doc appears to declare the SDL_Rects as global variables. Which class and specific SDL_Rect are you referring to?

and i will have to make different set_clips() functions for the different level platforms?

Your set_clips() method looks generic enough to be reused. You would just call it again for the platClipsp[] array of RECTs for the next level platform.

is there no way in which i can use one function and SDL_rect to do the above?

There's always a way, but that's not necessarily the best solution. Clean, clear, well-thought-out code isn't required to get a program running, but it helps a great deal when you want to come back and fix something you missed the first time, or add a feature.

I may be wrong, but it sounds like you don't really have a firm sense of which classes should be responsible for various aspects of the functionality. I don't know what all of these various Clips are (maybe bounding-rectangles for collision detection?) or why they're global variables instead of attributes of various class instances, but maybe if you slow down, and think about what the objects are in your game, the answers will become obvious: so far you have a "Stick" (the guy you move around?), a …

raptr_dflo 48 Posting Pro

couldn't i store the tokens first then see if whatever is stored to be valid, and once it checks out good it'll take the next 1,2,3 tokens for whatever object and send it to a function to calculate the measurements?

Of course you can. I was offering up one potential design for "a function that would take the next 1,2,3 tokens for the object, and calculate the measurements." In an object-oriented paradigm, an instance of a particular class would be responsible for that functionality -- the constructor (method with the same name as the class) would take the tokens, assign them to meaningful member variables, and maybe determine as part of that process whether there are the correct number of tokens and each is the expected type; separate functions that compute the desired output values for that shape can be instance methods; and printing out the resulting line can be another instance method.

There is additional thought required as far as which object (or function) is responsible for reading the input and determining which kind of shape-object to create (possibly a factory class), and how it knows how many tokens the shape-object needs (possibly a class method for the specific shape). All of this can be done with relatively simple data structures and non-object-oriented functions, but then why use C++? Of course, it also depends on what material your class has covered, and what the expectations for the assignment are, other than producing the correct output for the given …

raptr_dflo 48 Posting Pro

First, yes, your inclusion of the line using namespace std; at the top of your program means you don't have to specify std:: before cin/cout/cerr/endl throughout your code (but posting goddess Narue will yell at you for being so all-inclusive ;-P).

Then I think you CAN make a bunch of triangles! For each line of output and character position within that line, think about where you are in relation to each triangle (hint: there are four squares, each divided in half along a diagonal, and each character position is above/below/on that diagonal), and therefore which character to draw at that position.

Start with just the first triangle, maybe with a vertical line to the right, so you know that you're writing out the correct number of empty spaces. Then add code to do the next triangle, and so on. Let us know how it goes!

raptr_dflo 48 Posting Pro

In fact, if you've gotten as far as inheritance in your class, think about what's shared across all shapes: they take a set of tokens, determine whether the tokens are valid (as Vernon started you out with), and they print out some info. As long as the specific info isn't needed anywhere except inside the displayInfo() method, you can derive each shape from a base class Shape:

class Shape
{
protected:
    bool valid;
public:
    Shape(char *tokens[]);
    bool isValid();
    void displayInfo();
}

class Circle: public Shape
{
protected:
    double radius;
public:
    Circle(char *tokens[]);
    double Circumference();
    double Area();
    // isValid and displayInfo are already declared by Shape, we just re-implement them here
};

Circle::displayInfo()
{
    cout << "CIRCLE ";
    if isValid() {
        double circumference = Circumference();
        double area = Area();
        cout << "radius=" << radius << " area=" << area
             << " circumference=" << circumference << endl;
    }
    else
        cout << "invalid object" << endl;
}

If you haven't covered inheritance yet, don't worry about all this, just check whether the first token is a recognized shape-name, and if so, do the right thing with the remaining tokens.

raptr_dflo 48 Posting Pro

We can probably help again, but it would be useful to know what your new problem is. :) As usual include (1) what you're trying to accomplish, (2) the code (or an appropriate portion of it) that you've written so far, (3) what it's doing wrong, and (4) what you've tried so far that hasn't worked for you. We don't ask this to be annoying, it actually helps you: learning how to ask for help in a clear way actually forces you to think through your own problem in an organized manner, so that you can start seeing how to fix issues without actually needing to ask the questions!

raptr_dflo 48 Posting Pro

C++ is an extension to C. In addition to iostreams (and fstreams and stringstreams), it provides per-type operator-overloading and inheritable class objects. C code -is- valid C++, and an example as simple as yours doesn't need to be "converted". However, if you're learning C++, might I suggest that you start by understanding what your brother's program does (and how, and why), and then create a class that you can instantiate with any values for ROW and COL. I'll give you a start:

class Funny
{
protected:
    int width;
    int height;

public:
    Funny();  // default constructor
    Funny(int w, int h);  // constructor that takes a specified size
    void Draw();
};

Funny::Funny():
    width(13), height(4)
{}

Funny::Funny(int w, int h):
    width(w), height(h)
{}

void Funny::Draw()
{
    // use cout to layout spaces and stars in whatever way you like,
    // according to width and height
}
raptr_dflo 48 Posting Pro

Hmmm, I think successcounter++ does the right thing if successcounter is a double (successcounter += 1.0), but it's not my favorite. Since it's a counter, I'd prefer to keep it an int, then cast the math to double to perform the division at line 72. Float values can be deceptively weird, simply because they can't exactly represent values in binary that are obvious in decimal. For fun, try the following:

float val = 0.0;
while (val < 100.0) {
    std::cout << val << std::endl;
    val += 0.2;
}

Of course, integers -can- be represented exactly, over the range you're looking at, so it shouldn't be a problem. I just cringe anyway. Sorry.

But now that your code is a manageable length, each time through the loop you can print out: starting itemlevel, chanceofsuccess, chanceoffailure, upgrading, upgradesuccess, upgradefailed, upgrading again (if rolling for itembroken), itembroken, resulting itemlevel, successcounter and failcounter. That should tell you exactly what your problem is! :)

raptr_dflo 48 Posting Pro

The default malloc() routine in stdlib (going back to C days here) isn't particularly fast, in addition to potential issues with fragmenting memory. So the "normal" way to create a 2D image would be something like:

float ***image = (float ***)malloc(height * sizeof(float**));
for (row=0; row<height; row++) {
  image[row] = (float **)malloc(width * sizeof(float*));
  for (col=0; col<width; col++)
    image[row][col] = (float *)malloc(3 * sizeof(float));  /* 3 channels per pixel */
}

and freeing up the image would be just as cumbersome, just so you could get at the blue part of the top-right pixel via image[0][width-1][2] Instead, since I know that in addition to the width*height*3 floats, I also need width*height pointers for each pixel and height pointers for each row, I can make a single call to malloc:

image = (float***)malloc(width*height*3*sizeof(float) +
                         width*height*sizeof(float*) +
                         height*sizeof(float**));

and then painstakingly fill in the pointers to the correct offsets into the data. Because in this case I know that a float is 32 bits and a pointer (on a 32-bit machine) is also 32 bits, there's no issue with data alignment or padding. And since I allocated it with a single call, I can also free it with a single call: free(image); Whether the savings are worth the costs is entirely dependent on the usage scenario. When you're processing thousands of 4K x 3K images every night, each through several different image-processing steps, spread across as many workstations as you can get your hands on (for the case of a …

raptr_dflo 48 Posting Pro

I would suggest putting a LOT of cout's in your code, so you can see exactly what it's doing each time through the loop.

For instance, your upgradefailed case probably shouldn't reduce the itemlevel of the item. You may want to print something out in that case, but I would imagine the itemlevel should stay the same.

Also, since your code is nearly identical for each itemlevel, it's worth simplifying your program using some arrays (and maybe even structures). Pseudocode follows:

int chances[][2] = {{100, 0}, // chance of success, chance of failure
                    {100, 0}, // 100% chance of success for first three levels
                    {100, 0},
                    {80, 0},  // 80% chance of success, no chance of failure
                    ...
                   };

...
int chanceofsuccess = chances[itemlevel][0];
int chanceoffailure = chances[itemlevel][1];
if (requiredlevel > itemlevel) {
    upgrading = rand() % 99 + 1;  // this will always be an integer between 1 and 100, simplifying your if-expressions
    if (upgrading <= chanceofsuccess)
        upgradesuccess = true;
    else
        upgradefailed = true;
    if (upgradefailed == true and chanceoffailure > 0) {
        upgrading = rand() % 99 + 1;
        if (upgrading <= chanceoffailure)
            itembroken = true;
    }
    // do the right thing for the case of upgradesuccess or itembroken
}

I apologize if my C++ syntax is broken anywhere.

If you can use the same code with different data for each itemlevel, it's much less likely that one specific place in your code will be broken, and it's easier to print out all your values to see what's going on when you don't have to do it in a dozen places (and then clean it up when you're finished).

raptr_dflo 48 Posting Pro

Ah, integer division. successcounter is only ever zero (if you break your item before it levels up to the desired level) or one (if your item levels up to the desired level without breaking). (1 / howeverManyAttempts) will evaluate to 0 if (howeverManyAttemtps > 1). Instead do (at line 164):

percentage = double(successcounter) / counter;

to force it to do floating-point (or in this case double-precision) division, returning a reasonably accurate value between 0 and 1.

Also, now that I read more closely, I think you want your while expression at line 32 to read:

while ((itemlevel != requiredlevel && itembroken != false) && counterfinished == false){

(Alternatively think of it as "I want to quit when a) itemlevel == requiredlevel or b) itembroken == true or c) counterfinished = true, whichever happens first" ... that's the same as "I want to keep going as long as (not a and not b and not c)")

raptr_dflo 48 Posting Pro

Hi massivedynamic,

Don't worry about being new to the command-line, we were all there at some point, and the best way to become more comfortable is to keep at it.

>> use command-line flags to make sure it builds the static library libpdcurses.a
I was referring to potential optional command-line flags to ./configure, I'm looking in more detail now. Trying just the default './configure' (with no flags, should work for most cases) ... looks like I don't have sys/ipc.h header installed, so I'd have to update my cygwin installation to proceed.

In any case, after poking through a good portion of the 'configure' script, I don't see any obvious indication that there's an option to build static versions of the library, so forget that.

I'm hoping somebody with more recent memory of how to force static linking will hop on this thread!

raptr_dflo 48 Posting Pro

At line 32, you have:

while (exprA || exprB && exprC) {

Without regard to whether the (exprA || exprB) is correct, the && operator takes precedence over the || operator, your intent probably requires parenthesizing the ||-part:

while ((exprA || exprB) && exprC) {
raptr_dflo 48 Posting Pro

This time, you have defined

SDL_Rect levelOnePlatform [1];

but you're still calling

levelOne.set_clips(levelOnePlatform, 50);

which is probably overwriting all kinds of other memory!

raptr_dflo 48 Posting Pro

overlapping responses!

Your notation if (upgrading >=0 <= 25) is incorrect, instead:

if (upgrading >= 0 && upgrading <= 25)

Also, your rand()%1 isn't doing what you want, though rand()%100 will get you close. For an artificial example of "close", if rand() returned integers between 0 and 101 inclusive, then rand()%100 would get 0 or 1 twice as often as any other value.

raptr_dflo 48 Posting Pro

As far as picking random percentage chances, try:

#include <stdlib.h>
[...]
double val = double(rand())/RAND_MAX;  // get a random number between 0 and 1
if (val < 0.35) {
    // there's a 35% chance of this being true
    upgradesuccess = true;
}

or if you prefer percentages between 0 and 100:

double val = 100.0 * double(rand())/RAND_MAX;
if (val < 35.0) {
    // there's a 35% chance of this being true
    upgradesuccess = true;
}

To do something like your combined percentages:

double val = 100.0 * double(rand())/RAND_MAX;
//30% chance item will succeed 25% chance the item will be destroyed
if (val < 30.0) {
    // there's a 30% chance of this being true
    upgradesuccess = true;
}
else if (val < 55.0) {
    // there's a 25% chance of the value being between 30 and 55
    itembroken = true;
}
raptr_dflo 48 Posting Pro

Hmmm... the whole premise of public-key encrpytion is that keys need to be shared, to some extent. You can still hard-code the keys you need into the sender application and the receiver application (rather than generate and exchange keys at run-time), but putting one key at each end shouldn't be sufficient.

How strong does your "encryption" need to be? If obfuscation is your goal, consider doing something like:
+ bitwise-XOR each 4-byte segment of the data against a fixed 32-bit integer
or (somewhat harder to decipher):
+ bitwise-XOR the first 4-byte segment of the data against a fixed 32-bit integer
+ then for each successive 4-byte segment, bitwise-XOR it against the result of the previous segment

For something a bit more encryption-like, search up "Blowfish". If you need actual strong encryption, then you have to follow the steps required by the scheme. If there were a shortcut, the encryption would be compromised!

raptr_dflo 48 Posting Pro

How is this a C++ question, and what does it have to do with Facial Expression Animation?

http://lmgtfy.com/?q=asf+file

raptr_dflo 48 Posting Pro

If it were only that easy! You need code that can determine which computer to talk to (given a URL), open a socket connection to that computer, make a request for the contents of a specific file, read the contents over the socket connection, and write the contents into a file on the local filesystem. Luckily, you're not alone, and there are various existing packages that do all the dirty-work for you. Take a look at libcurl.

raptr_dflo 48 Posting Pro

While it doesn't address your problem, you have a typo at line 15 (fillValue should just be a float, not a float*?), and a potential memory leak at line 48 (check whether buffer is non-NULL and if so free up the previously allocated memory before assigning a new chunk).

Personally, I dislike using the same names for method arguments and class members, as in setDimensions(), since the arguments mask the members and require the use of 'this->' to disambiguate. But that's just my preference.

Finally your constructor starting at line 15 also doesn't initialize the width and height members of the instance, possibly a logic error resulting from using the same names! ;)

I assume you're just testing something out, but func() would be better named newWithSameSize() or something else descriptive.

Now if I could just see what the problem with your new instance could be....

raptr_dflo 48 Posting Pro

WaltP,

In general I agree with you; however, converting a couple of substrings to integers is not a lot of "wasted work" if you determine that the last character is invalid, and is it any less wasteful to iterate over the same string in two separate functions, once to verify the character-by-character validity and again to extract the values? Also, checking that a couple of successive characters are digits could well be considered a valid part of the task of converting the substring to an integer. Be wary of turning good advice into a religion. :)

And to you new programmers, listen to Walt, he's really good at what he does!

raptr_dflo 48 Posting Pro

Correct enough. SDL maintains the queue of events for you, so all you're doing is checking whether there's an event on the queue and if so, retrieving it so you can decide what to do about it.

After line 7, consider adding a 'break;' statement so that you don't have to check whether the event-type is all of the other possible options before exiting the event-queue-polling loop (which you have to do at -some- point anyway, so that you can get back out to the while(program) loop).

raptr_dflo 48 Posting Pro

Adding a function should be sufficient. Since you already have code that can step through a date-string and divide it into pieces, it should be easy for you to write a function that steps through and verifies that the pieces are the correct length and contain valid characters.

Or you could combine the two into:

  • check whether the first two characters are numeric digits
  • if so, convert to integer
  • check whether the resulting integer is between 1 and 12 inclusive
  • check whether the next character is a slash
  • ...

and if everything succeeds, copy the integers into your date-struct object.

raptr_dflo 48 Posting Pro

... is there a way I could combing that .dll file with the executable?

The sarcastic answer is "yes, make a .zip file that includes the .exe and the .dll file". :)

A different (and somewhat painful) option is to use a Windows package builder (I believe NSIS is free) to package the .dll and the .exe into an installer executable.

A third options is to download the PDCurses source and build the static library yourself:

  • start from the same link where you got the DLL, navigate to pdcurses -> 3.4, and download pdcurs34.zip
  • run './configure' (possibly with command-line flags to make sure it builds the static library libpdcurses.a) and then 'make'
  • then use one of the command-lines above to link the static library into your .exe (you may also need a -L/path/to/dir/containing/lib flag so the compiler can find the static library you just built).