~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

So atleast try out something you have in your mind and post it here. Help will automatically ensue..

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Two problems I can see:

• Your memory allocation is not proper. Each of your rows share a common vector variable because of the stmt:

vector<int> v(n);
vector<vector<int> > data(n,v);

Here the memory for each inner row is getting allocated only once and your two dimensional matrix gets populated with the same vector.

You need to change it to:

vector<vector<int> > data(n,vector<int> (n));

So that the memory allocation occurs for each row rather than only once for all rows.

• Your logic is skewed. The line :

i=0;
    j=n/2;
    for (int k=1; k<=nsqr; ++k)
    {
        data[i][j] = k;
        i--;

is bound to produce an out of bounds error since you are decemeneting i which already is zero, resulting in its value becoming -1, which is not a valid index.

Better use size_t instead of int for index variables to make sure you don't invade the out of bounds exception land. (assigning -ve values to such variables leads to a warning which is fairly easy to decode).

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

In that case, it would be a good idea to mention at the beginning that the given method is not the best and there are better alternatives since beginners are known to grasp both good and bad equally well.... ;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I have written pages for my site regarding that issue. To you it is not intuitive. Unless the newbie has a very large string, using strlen isn't a truely bad thing to do; because it will not have to loop many times through each element to get the legnth each time the for loop, loops.

Programmer's don't take anything for granted. The usual "the string can't be that long" thing just doesn't cut ice in a practical setting. A piece of code which makes repeated calls to a function inside a loop will always perform worse than a function which doesn't, no matter how forgiving the compiler is.

I was just being a smartass as you were being - so it seemed.

*ahem*

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You need to invoke the program from the command line using the executable created after the compilation process to work.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Thanks for the nudge in the right direction!

You are welcome..... ;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Something like this ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Your problem area is:

strcpy (rstring, string);
rstring = (char*)malloc (sizeof (char) *strlen(string) + 1);

You need to first allocate the memory and then perform string copy and not the other way around.

Also, you don't need a temporary for this purpose. You can always do in place swapping.

char* reverse_string ( char* my_str )
{
    char tmp = '\0' ;
    int i, j ;
    int str_length = strlen (my_str) ;

    for ( i = 0, j = str_length - 1; i < j ; ++i, --j )
    {
         tmp = my_str [i] ;
         my_str [i] = my_str [j] ;
         my_str [j] = tmp ;
    }

    return my_str ;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

hmm, why did you put (char*) in brackets?

Its called casting . In this specific case its the casting of void pointer retuned by malloc to a pointer to a char.

also whats malloc? like what does the variable stand for? or are you calling by value?

A litte google would have answered your question nicely. Like this.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Why not use the first ENUM set for the second selection also ?

Either that or prefix the ENUM names with an abbreviation of their purpose. Something like:

enum MenuOne { MO_FIRST = 1, MO_SECOND } ;
enum MenuTwo { MT_FIRST = 1, MT_SECOND } ;
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

<< mistake >>

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Either using :

const char* ptr = param ;
// or
char* ptr = const_cast<char*> (param) ;

But it would be interesting to know what you are trying to achieve here.....

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Post your code so that we can atleast point out the mistakes you are making...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Just a minor point, better use ++variable instead of using variable++. If done so prevents the creation of a temporary variable. This is a normal hack used by all programmers.

• Pre-increment(++a) - Increment the value of variable and then use it.

• Post-increment (a++) - Use the value of variable and then increment it.

Since we just want the value of variable to be incremented, just use pre-increment.

John A commented: Thanks for the info :) - joeprogrammer +6
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Maybe this would interest you...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Linker errors are usually generated when the linker can't find the function definations i.e. the body of the mentioned functions.

You need to place the "Serial.h" and "Serial.cpp" file in the same directory as that of the main or driver file and make sure the above mentioned functions are defined in the "Serial.cpp" file.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I guess what I would like to know..., is there a way I could change the value in the string array using the pointer?. Or I will always need to initialize the array with the string?.

Actually there are many ways to change value of a character array using a pointer to it...

// Untested !!!

int main( void )
{
    int i = 0 ;
    // first way -- initialize while declaring
    char arr[BUFSIZ] = { '\0' } ;

    char* ptr_arr = arr ;

    // second way -- use string copy
    strcpy( ptr_arr, "Hello" ) ;
    puts( ptr_arr ) ;

    // Third way -- use fgets( ) or any other function which accepts user input
    puts( "Enter the string: ") ;
    fgets( ptr_arr, BUFSIZ, stdin ) ;
    puts( ptr_arr ) ;

    // And many other ways like looping through the entire array
    // and setting up individual characters
    putchar( '\n' ) ;
    for( i = 0; i < BUFSIZ - 1; ++i )
        ptr_arr[ i ] = '0' ;
    ptr_arr[ i ] = '\0' ;   // add a null terminator at the end
    puts( ptr_arr ) ;


    getchar( ) ;
    return 0 ;
}
Dave Sinkula commented: Thanks for doing my cleanup/followup. I was meaning to get around to it... --Dave +9
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Minor nit, ~s.o.s~, the initial examples by the OP were expressions and not declarations.

Oh didn't read the question properly, assumed that it dealt with declarations -- thanks for pointing out the blunder.

Anyways considering he is a beginner, the link is a good read nonetheless. ;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Maybe this will help you out.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

One more thing, plz tell why is it preferrable to use int main(void) and return 0 rather than simply void main() . thnks a lot

Because that is what the C standard says.. ;)

There are only two correct prototypes for main( ) :

  • int main( void )
  • int main( int argc, char* argv[] )

And only three valid values which main can return:

  • return 0
  • return EXIT_SUCCESS
  • return EXIT_FAILURE

Anything else is implementation / platform dependent and may make your code non portable.

So in the end the whole hassle is about keeping your programs portable and makign sure that a standard exists which every C / C++ developer follows.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Not to forget that getch() is not a standard function, some compiler support it, some don't. Use the portable equivalent getchar() to achieve the same purpose.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Welcome S.O.S to the Python crowd. We are all quite nice in Python land, just here to learn more!

Thanks for squeezing me in...:mrgreen:

Small Miss Steaks are accepted, gives the rest of us the opportunity to show off how smart we are.

Aha..thought something was fishy the way you said "No cigars on that one ~s.o.s~"..:twisted:

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

No cigars on that one s.o.s, here is the result

Doesn't make a difference, I don't smoke anyways...:mrgreen:

And btw Jeff, thanks for correcting my code in my absence, would have done that anyways...:p.

Maybe should run my programs before I post them here...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Since the data is coming from a raw source (text file, database, user input...) wouldn't it be nice if we didn't assume that the "[" will always be the first character of "txt" and "]" is not always the last character of "txt".

Given that the data can also be of the form " [ 32] " or "[32 ]". To handle such situations here is what I have come up with....

data_raw = """[20 ]
[ 35 ]
[40  ]
[84 ]
[100 ]
[ 245]
[  260]
[ 300 ]
[ 440 ]
[   521     ]
[ 650    ]
"""
data_list = data_raw.split()
print data_list  
data_list2 = [x.strip(" []") for x in data_list]
print data_list2
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I guess you should read with more concentration....

int fflush(FILE* stream);

Flushes stream stream and returns zero on success or EOF on error.

Effect undefined for input stream. fflush(NULL) flushes all output streams.

The effect of fflush is undefined on the input stream as it was always meant for output file streams for forcing the output onto the screen.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

try using...
fflush(stdin);
after every gets();

Bad, bad really bad. Read this.

Salem commented: More power pills than pacman - Salem +5
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes rightly said -- its known as [search]Double buffering[/search] in which the next frame to be drawn is written to the RAM (in case of software implementation) or the the VRAM (hardware implementation) and is then displayed on the screen in the next frame.

Just FYI, there is also an advanced way to achieve it known as [search]Triple Buffering[/search].

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes he could, but that's not what he wants to do. And it would look terrible and be awfuly sloooooow if there were a lot of graphics on the screen such as you might see in games.

But thats what happens in real games -- the whole screen in cleared and the updated graphics are redrawn.

As a matter of fact, this is the very way display devices work. The whole screen is erased and redrawn and the frequency of that depends on what we know as the refresh rate of the monitor. (normally measured in Hertz)

And strange enough this is the very way API's like DirectX and OpenGL work, erasing the screen and redrawing the next frame.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Set the Border Style of the form to 0 along with the Window State to be maximized.

Don't forget to add a "QUIT" button to the form otherwise you won't be able to quit the application.

Another way of doing it the hard way is mentioned here.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I too have tried making a game engine, but lost interest in OpenGL, so my engine is sitting here on my computer, half-written... Meanwhile I'm working on a project that's so secret I won't even tell you guys until I'm done. :twisted:

Hey Joey, any specific reason why you dumped the project ?

And btw, mind telling us about your next killer app.. ;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Ah..I thought you were doing it for money, but if not, then I would recommend you to take the most difficult path and learn the maximum you can. :D

Btw, do keep blogging and if I get time, I would surely read them...;)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

In the form properties of your MDI form, set the "window state" property to "2 - Maximized" and you would get a full screen application.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Wow it sure is a good breakdown.

But still building a game engine from scratch is what bothers me the most and is one of the things which can mar the completion of the project....Good luck to you and your Pirates. :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Update: Btw what does the program exactly do ? Convert a number to binary is it ?

I am unsure because for the input 1 the output given is 110001 which is rather err..incorrect for a binary representation of 1 . Is this what you intended wheelz ? Ditto with Raye's code ? Am I missing something here...?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

WOW, that really was a good one Raye. Maybe I should have being more verbose in my first post.. :P

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Actually too much documentation, I would say that a complete overkill. You just need to provide a short abstract on what your algorithm does rather than clubbing the program to death by explaining each and every statement.

I don't know if you have reflected on this but almost 50% of your code is comments which is actually a bad thing...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I don't know what kind of expertise you hold in the programming languages you would be using (C++, Python ?) or in OpenGL or DirectX but still I wish all the best to you.

Hope this project doesn't come out to be only a pipe dream due to lack of time / expertise / domain knowledge.

BTW which API you using to develop the game ? Is it a 2D or 3D game?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Have you got the graphics.h and the BGI file in the same location as that of your program ...? And btw post all the error messages, so that it would be easier to spot the problem.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I guess thats because when you open your file the next time, you don't use the iostream flag append and thats the reason your previous contents get erased.

A file which already has contents when opened for writing needs to be opned in append mode for preserving the previous contents. More information and example here.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

How can I run some code when I click on an arrow of a data control?

Drag the ADODC control onto the form (by importing the component Microsoft ADO Data Control ActiveX Control using Project -> Coponents), double click on it.

Write all the code you want in its "WillMove" event. For more help, post a concrete explanation and example from your side.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hello there.

well, It got a little bit of data when I do it that way, but still gave the same output after a few thousand bytes. I think it's a copy-protection thing. I don't know how to get around that though.

I hope you realize that getting around the copy-protection thing constitutes a form of piracy even if you own the game. Getting around this protection is what exactly the pirates do before making copies of the game and selling them illegally. Searching google for "getting around copy protection" will make you realize in which direction you are heading.

It would be really a good thing if you stopped this discussion right there before some other *strict* mod comes around and drops you an infraction.

Thank you.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

size_t is a macro which is declared in stddef.h while defined in the header file string.h It normally amounts to the same as unsigned int or unsigned long depending on the compiler implementation. Most of the functions of string.h require size_t hence it has been used, though you could have used even signed int and got away with it, pushing the responsibility of type conversion on our dear old compiler. :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Bearing in mind that if this is a console application, there's a finite number of characters for any given line which you can output without the code spilling over to the next line, and completely ruining your formatting anyway.
Therefore, it may be simplest to put in an upper limit to the number of lines the program can produce, given the constraints of your environment.

...or better yet to redirect your output to a text file which can hold virtually infinite data, thereby removing the need for an upper limit.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hello there.

You're right - I guess I was thinking in terms of dynamic memory allocation...

Ah..just to clear the matters up...even if we dynamically allocated 2.9KB of memory, it wouldn't be such a problem, unless of course, you were doing realloc i.e. allocating memory during runtime and exceeding the limitations imposed by the current memory model of the compiler.

Thank you.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hello there.

Either that, or you have some miniscule amount of RAM in your computer. What's your compiler? It's highly unlikely, but a crappy old compiler has much different limits than a modern one.

Yes, an old compiler imposes a limit on the amount of memory that can be allocated to a single variable, but if that were the senario, the program execution would have halted at the point he has declared the three dimensional array.

I hope you realize that even though he hasn't stored any values initially in his array, the space has been nonetheless allocated to him. I don't think any failed attempt after the allocation is due to the old compiler.

And as far as RAM is concerned, he is allocating 729 * 4 bytes ~ 2.85 KB. I don't think this should be as such a problem...;)

Thank you.

John A commented: Correct you are :). -joeprogrammer +4
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

C'mon people. C++ is C++ whether TurboC Ver 1 or MSVC.NET (for the most part).

Not when you have a deadline to meet, in that case having a really good IDE helps big time.

And I can guarantee the problem exists no matter what compiler he uses, so please let's concentrate in the OP's problem rather than an upgrade that produces a non-fix.

A bit correction....lets concentrate on an upgrade that keeps him away from non standard programming.:twisted:

But yes, back on topic, danijohn post your code so we can have a look at it. Maybe then we would be able to help you better.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Depends on what exactly do you mean by a company -- a big time software gaint or a small time budding organization with no more than 10 people.

If the former, then yes, you are correct. But if the latter, then no, I have seen small time companies (like those in embedded development etc.) using free IDE's like Code::Blocks and Dev C++.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Here a LINK to a screenshot of the cmd window showing bat results.

It seems that the test file HelloWorld.py is not being recognized; it is in the same directory so I do not understand why this is.

Hmm....you can try this.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Using: py2exe-0.6.5.win32-py2.5, Python 2.4.3 (IDLE)

There's your problem. IDLE was never quite finished. The Run Module in the Run menu doesn't pass any command line arguments that way that other IDEs do. Follow all the steps in tutorial.

:D
Maybe you should just read the link I posted and the original thread.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hey Sharky, maybe something like this is what you are looking for.

mattyd commented: always helpful and a good member of Daniweb- Sharky +1