Salem 5,265 Posting Sage

Game game;
goes in ONE .cpp file.

Say draw.cpp then.

Salem 5,265 Posting Sage

In draw.h, you should have
extern Game game;

In game.cpp, have
Game game;

Salem 5,265 Posting Sage
Salem 5,265 Posting Sage
cline = new char[sline.length()+1];
			strcpy(cline, sline.c_str());

			chr = strtok(cline,",");
			data.ticker +=string(chr);
			fileName +=string(chr);

			aChr = chr;
			strcat(aChr, ".txt");
			fileName =string(aChr);

This happens on your char array, where there is only just room for the characters you read, nevermind adding .txt to it.

1. You're always doing fileName += something
it gets longer and longer.

2. Add the suffix with
fileName += ".txt";
rather than messing with the char array.

IMO, you should learn how to do this kind of thing with a std::string, rather than running to c-style strtok() for short-term convenience. You only typed a few lines, and it blew up anyway.

> And second - you try to free the memory, which was not allocated dinamically.
True, but deleting NULL is harmless.

Salem 5,265 Posting Sage

You can't insert into a text file.
Read the whole thing in, make some changes, then write it all back out again.

But as it seems to be XML, there's bound to be some handy class which makes easy work of serialising the data, and with access methods which allow you to traverse the document tree, and make changes to it.

Salem 5,265 Posting Sage

You're opening the file in append mode.
Are you sure you're not looking at the data from previous runs, where you might have had a different order to the data?

Salem 5,265 Posting Sage

So what have you learnt (or even attempted) in the past two weeks?
http://www.daniweb.com/forums/thread208111.html

Salem 5,265 Posting Sage

> double monthlyInterest = interest * 12;
Not divide by 12 ?

> double interest = 5.7;
I think this is 570%
Seems high to me.

Salem 5,265 Posting Sage

> if(qtnNo = 1)
Surely == 1

Also, use the debugger.
- Put a breakpoint on the line which generates the segfault.
- Run the code, let the debugger trap the breakpoint
- You can then have a good look round all the data structures and try to figure out what went wrong.
- Put other breakpoints earlier in the code, say single step the insert into BST function.

Salem 5,265 Posting Sage

If you're really going to run the executables on real DOS, then take a look at this information.
http://www.cs.cmu.edu/afs/cs.cmu.edu/user/ralf/pub/WWW/files.html

Salem 5,265 Posting Sage

Yes, it's OLD C, and it defaults to int.

tux4life commented: Shortest working answer of the week (previous)? +19
Salem 5,265 Posting Sage

Lemme guess, you're running TurboC on XP?

Do you want the information for the VM TurboC runs in, or the real machine XP is running in.

I run XP inside VirtualBox, so there are now 3 possible answers to your question.

Salem 5,265 Posting Sage

> First-chance exception at 0x004185bc in BinaryTreeGame.exe: 0xC0000005: Access violation reading location 0xcdcdcded.
Heap memory (in debug mode) gets filled with 0xcd when you free it.

> inorder(p->llink); //<-- there is a yellow arrow pointing here
p or p->llink is pointing to a node which no longer exists.

Did you miss a p = NULL when deleting a node?

Salem 5,265 Posting Sage

Debug assertions usually show up when you fail to do proper error checking.

Eg.

FILE *fp = fopen( "missing_file.txt", "r" );
// no check for success
int ch = fgetc( fp );  // debug assert here
Salem 5,265 Posting Sage

> actually this could not be termed as unexplained behaviour
I'm assuming that you didn't actually bother to read my post at all, or any of the links posted therein.

Statements like "My compiler does...." are meaningless.
Read the FAQs, and better yet, the standards.

If you write code like that, you're in for one hell of a surprise at some point - just check my results - utter chaos.

Salem 5,265 Posting Sage

Congrats AD :)

> Now this is a marriage to be proud of Married 83 years, they have 186 descendants.
A birthday to remember every other day - that's gotta be hard work.
"What are you doing? Buying a present. Who for? Dunno, bound to be someone's either today or tomorrow".
Mind you, come xmas, it's payback time :)

Salem 5,265 Posting Sage

The OP posted code AND an example - read it.

Salem 5,265 Posting Sage

> Isn't so a virtual address is allocated to it by the compiler.
It's a directive generated by the compiler to the linker, which basically says

If there is an actual definition of 'a', then use that.
If there is no definition of 'a' anywhere, then make an a=0 and use it.

$ cat prog.c && gcc prog.c && ./a.out 
#include <stdio.h>

int a;

int main ( ) {
  printf( "%d\n", a );
  return 0;
}

0
$ cat prog.c && gcc prog.c && ./a.out 
#include <stdio.h>

int a = 42;

int main ( ) {
  printf( "%d\n", a );
  return 0;
}

42
$ cat prog.c && gcc prog.c && ./a.out 
#include <stdio.h>

extern int a;

int main ( ) {
  printf( "%d\n", a );
  return 0;
}

/tmp/cca1uyC4.o: In function `main':
prog.c:(.text+0x12): undefined reference to `a'
collect2: ld returned 1 exit status

First one is a tentative definition (assumed 0).
Second is a proper definition with an assigned value.
Last one is a declaration (which doesn't exist elsewhere), so it becomes unresolved at link time.

Salem 5,265 Posting Sage

Memory can be trashed in many ways.

Running off the end of the array

int length = 10;
int *p = new int[length];
for ( int i = 0 ; i <= length ; i++ ) p[i] = 0;

<= should be <

Freeing the same memory twice

int *p = new int [10];
delete [] p;
// more code
delete [] p; // oops

Freeing what wasn't allocated

int *p = new int [10];
// code
p++;  // say walking the array
delete [] p;  // oops, this isn't what new returned

Edit:
I wrote this, then saw your fix, so I posted it anyway.

Salem 5,265 Posting Sage

I've no idea then.

Did you start with an empty Win32 console project?

Salem 5,265 Posting Sage

> int a; //which is a definition
Actually, this is just a tentative definition
At the point of compiling it, storage space is not yet allocated to it, so you won't find it as such in the object file.

If you said nothing else, then the linker would create a single
int a = 0;
for you.

Or if you had exactly ONE
int a = 42;
in one of your source files, then all the other int a; would refer to that.

tux4life commented: Very interesting link :) +19
Salem 5,265 Posting Sage

Read the intro threads on how to use code tags.

Salem 5,265 Posting Sage

It's a pretty sure thing that you're looking at the effect rather than the cause.

Something else is probably trashing memory. Here is just where you first notice there is a problem.

In a correct program, there is no apparent difference between debug and release (except speed). That you are observing a difference is a sure sign of bugs.

It depends on how large the program is as to what to do about it.

One thing to do is examine carefully all your other classes. Especially any where you call new/delete explicitly.

Salem 5,265 Posting Sage

Sounds like the crappy PCH strikes again.


Try turning PCH off.
It's only relevant if you're compiling vast projects which are pretty stable.

Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

> #include<iostream> using namespace std; Although its not good
Except it appears to be a C program from the logs.

But then again, who knows, the whole mess was posted without code tags to begin with. Don't people READ intro threads? Of course not, that would get in the way of being nice to readers.

> warning C4013: 'rand' undefined; assuming extern returning int
You're missing stdlib.h

And some others from the look of things.

Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

Probably because MS chose to make long double and double the same thing.

A long double is IIRC only 80 bits (10 bytes), but to preserve alignment, the compiler rounds out the size to a multiple of 4.

The underlying architecture isn't the whole story.

Running crusty old 16-bit turboc on your nice new machine doesn't magically make int into a 32-bit number.

Salem 5,265 Posting Sage

This is a catalogue of some experiments on just two aspects of undefined behaviour.

This was inspired by yet another long bout of explanation in a recent thread, so I thought it was time to dust off a bunch of compilers, and compare.

This is the test code.

#include <stdio.h>

int f1 ( void ) {
  printf( "f1 called = 1\n" );
  return 1;
}
int f2 ( void ) {
  printf( "f2 called = 2\n" );
  return 2;
}
int f3 ( void ) {
  printf( "f3 called = 3\n" );
  return 3;
}
int f4 ( void ) {
  printf( "f4 called = 4\n" );
  return 4;
}
int f5 ( void ) {
  printf( "f5 called = 5\n" );
  return 5;
}

/* Although * happens before +, there is NO guarantee that */
/* f1() will always be called after f2() and f3() */
/* http://c-faq.com/expr/precvsooe.html */
void test1 ( void ) {
  int result;
  printf( "Precedence is not the same as sub-expression evaluation order\n" );
  result = f1() + f2() * f3() - f4() / f5();
  printf( "Result=%d\n", result );
  printf( "inline=%d\n", f1() + f2() * f3() - f4() / f5() );
}

/* The nature of 'before' and 'after' is poorly understood */
/* http://c-faq.com/expr/evalorder2.html */
void test2 ( void ) {
  int i = 3, j = 3;
  int r1 = ++i * i++;
  printf( "Multiple side effects are undefined\n" );
  printf( "R1=%d, i=%d\n", r1, i …
kvprajapati commented: Excellent. You are absolutely right. +10
yellowSnow commented: Very good post and interesting results - you mad scientist you! +4
Dave Sinkula commented: Thanks for the effort of running it for all those compliers and settings and posting the results. +24
tux4life commented: Nice posting! I agree with the previous comments. +18
Salem 5,265 Posting Sage

> unfortunately I cant dump this compiler right now because our syllabus still follows it.
Until your country gets it's act together and starts teaching students something used in the real world, I won't worry about out sourcing.

Tell your tutor that this fossil is NOT preparing you for a life after college.

Salem 5,265 Posting Sage

> somewhen I changed the A & B drives around in BIOS
Can you get to this point again?
Even machines 10 years old have a lot of different options.
One of them should be C:, which would boot the OS off the primary hard disk.

Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

http://msdn.microsoft.com/en-us/library/7dzey6h6(VS.71).aspx
Visual Studio 6 for example defaults to ANSI
Visual Studio 2008 defaults to UNICODE

The Win32 API functions (like CreateFile) are already wrapped, but many standard functions in the CRT are not.

Also, you need to use the TEXT() or _T() macro for ALL your string constants.

Read the rest of the MSDN link.

Salem 5,265 Posting Sage

Begin with
while ( number <= 50 )

Salem 5,265 Posting Sage

Yes you should, and writing "I'm lazy" and grinning about it does you no favours.

Salem 5,265 Posting Sage

If you're creating a win32 console game, try
http://www.adrianxw.dk/SoftwareSite/Consoles/Consoles5.html

iamthwee commented: good link +22
Shankye commented: Nice one .. +0
Salem 5,265 Posting Sage

The threads at the top of this forum would be a start...

Salem 5,265 Posting Sage

Sounds perfect - go for it.

Salem 5,265 Posting Sage

My first suggestion would be to read up on functions, and then split main() into something more manageable (say 1 function per top-level menu option).

Several hundred lines of poorly indented code isn't good to read.

Salem 5,265 Posting Sage

Just so we're all clear, your instructor gave you a number of source files which approximately do what you want, but for some reason there are
- some syntax errors
- some missing functionality
which YOU are supposed to fix?

Have you fixed any?

Salem 5,265 Posting Sage

> How do I bind the up/down/left/right keys?
That depends on your OS/Compiler/Kind of program.
A Linux Console program has a different answer to a windows GUI program.

Yeah, it's just a loop with some inputs.

Salem 5,265 Posting Sage

> I have not spotted any mention of anything crashing in this thread!
The image says
"An unhandled exception in acrobat.exe blah blah blah"

Fixing the JIT won't make that go away, only replace it with something else (probably something like "would you like to send an error report to ...").

Salem 5,265 Posting Sage

> and i hope that those information will help you to minimize the search domain so you can help me.
It hasn't helped you, why do you think it will help us?

Look around, this forum is littered with "final year project" posts from a litany of people unable to think.

See, this is the final test which separates real software engineers who can innovate solutions, from the windowless cube-farm denizens who merely do as they're told.

Acquiring a bunch of certificates (i have three certificates from oracle) is basically a meaningless activity unless you've got the nouse to actually apply that knowledge to solving problems.

More scenarios:
You're at your first job interview, and you get asked "So what inspired you to choose this project?". Blurting out "some dude on a website told me to do it" will not go down well. And any other answer will be a lie.
You got the job (somehow), and you're asked "How would you solve this problem?". After a few "I dunno" answers, your colleagues will soon cotton on that you're just dead-weight.

Salem 5,265 Posting Sage

So add debug, print the actual request and go from there.

Salem 5,265 Posting Sage

A web search for e-voting and some reading perhaps.

Salem 5,265 Posting Sage

http://msdn.microsoft.com/en-us/library/5hs4b7a6.aspx
Includes how to turn it off (involves a registry edit, so exercise some care).

But that won't fix the underlying problem of why things keep crashing in the first place.

Salem 5,265 Posting Sage

http://info.borland.com/borlandcpp/turbosuite/turbo45.html
Turbo C++ 4.5 for Windows 3.1
16-bit C and C++ development for Windows

It isn't a DOS compiler, and it isn't an XP compiler.

Just because you managed to make "hello world" work doesn't mean that it's a good choice for all your future software development.

For a start, it's still stuck in a 16 bit world, where the max block for any single object is 64K and the total amount of memory you could ever have is around 1MB.

How much memory do you really have on your 32-bit XP machine?
You're trying to fill the bath with a tea-spoon!

Salem 5,265 Posting Sage

> Can I expect some speed increase using above options?
You can certainly expect a change, so you might consider that some of them would be quicker.
But saying which would be quicker in advance would be pure guess-work.

> If so, would it be significant?
Doubtful.
+/- 10% between the best and the worst would be an average.

Again, you might find compiler 'x' on OS 'y' to be particularly good, but you would only find it by accident rather than some predictable information in advance.

All compilers fundamentally implement the same algorithm (your code). Each in their own way is going to generate the code to do pretty much the same amount of work, which will take pretty much the same amount of time.

If you want to turn an hour into a minute, then you need a change of algorithm, not a change of compiler.

Salem 5,265 Posting Sage
if ( ReadBeforePosting() == true && PostHasCodeTags() == true ) {
  // reward OP with answers
} else {
  MoreCluesOnHowToDoBetterNextTime();
}
Salem 5,265 Posting Sage