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

GCC = GNU Compiler Collection, which is all of the compilers produced by the GCC team.
gcc = GNU C Compiler, which is just one of them.

Salem 5,265 Posting Sage

I thought they were porting GCC, not gcc

Salem 5,265 Posting Sage

gets() has no means of preventing buffer overflow - pure and simple.

> The gets() function has nothing to do with reading and writing into a file I guess.
True, but that doesn't stop us commenting on other horrors in your code.

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

> gets(name);
Why are you using this AWFUL C function in a C++ program?
Consider using cin.getline(), which as well as being C++ proper, also protects your char array from buffer overflow.

Salem 5,265 Posting Sage

<rhetorical>I'd like to know how you got to your final year by being so helpless.</rhetorical>
This is the kind of post we expect from noobs at the start of their first semester, not from someone who's been studying for the past 3 years.

On the plus side, at least you do have a project in mind, which is a lot better than a whole raft of other people incapable of even thinking up a project title (see posts passim)

> So can i get basic codings for communication between client and server using tcp/ip protocol??
Just to a search for "beej" on the net, it's a well-known tutorial.

What is a BE anyway? Bachelor of Engineering ?

Salem 5,265 Posting Sage

> how can I get around having to wait for an input from the user?
By using a function which tests to see if input is available, without actually blocking.

Pseudo-code. A rather abstract (and simplified) view of the main game loop. If you want to change while ( playerStillAlive ) to while ( nLives > 0 ) , that's easily done.

do {
  if ( keyboardHasInput() ) {
    key = readKeyboard();
    updatePlayer(key,player);
  }
  playerStillAlive = updateMonsters(player,monsters);
  if ( playerStillAlive ) {
    drawScreen(player,monsters);
  }
} while ( playerStillAlive );
drawDeathScreen();
Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

> while(!feof(fp)) {
> if(fgets(str, 126, fp))
You can say this more succinctly with
while ( fgets( str, sizeof str, fp ) != NULL )

A point to note, you don't have to adjust the buffer size when calling fgets.

Salem 5,265 Posting Sage

SDL = http://www.libsdl.org/

But before you get bogged down in specific APIs, I would suggest you get familiar with the core language.

Salem 5,265 Posting Sage

You don't need threads, just a means of reading all your input device(s) without blocking.
For example, this.

Salem 5,265 Posting Sage

My other suggestions would be to also consider Python and PHP, PHP in particular if you're into a lot of web stuff. Also on the "web-centric" list would be Javascript.

If your ultimate aim is to work professionally, then you'll end up knowing a couple of languages in depth, several more will be familiar, and yet more you'll be able to "get by with, if you've got the manual". With this in mind, which language you learn first doesn't really matter so much. And over a career, you'll learn new ones as well.

I was for example taught Pascal, but I never used it professionally, and I've never considered it a waste. It was just a practical manifestation of all the "how to..." information.

The choice for you at the moment is trying to decide which vehicle to buy without having learnt to drive. Nor have you decided whether you want to be in F1 or a road haulier.

For sure there are a whole set of skills unique to each, but there are also significant similarities across a very broad spectrum.

Continuing with the car metaphor, you'll want to practice in a nice easy car which doesn't bite back. C++ is a Ferrari. Fast and sleek to be sure, but also capable of being turned into instant wreckage unless you're careful.
C is also a Ferrari, but with somewhat loose steering, and suspect brakes ;)

The languages I mentioned above are good …

darkagn commented: Some good, friendly advice there and I especially like your car analogy :) +1
Salem 5,265 Posting Sage

> Can not compile from any other cme.exe.
Well the new PATH only takes effect in new cmd.exe files you run. Instances which were running before you updated the settings will not see the change.

Salem 5,265 Posting Sage

Did you update the PATH environment variables via the system settings dialogs?
From a new cmd.exe, does the 'PATH' command show the compiler install directory?

Salem 5,265 Posting Sage

You should only need the \bin directory in your path, as that also helps it locate the .cfg file where the include path information is also stored.

system or user?
The system path is what all user's of your machine will see. The user path is of course unique to you. If it's only you using the machine, it's a fairly moot point.

You can check the result by opening a new cmd.exe and typing 'path' to display the current path. If that shows the \bin directory, you should be good to go.

Salem 5,265 Posting Sage

Er, that is what "COMMA" in Comma Separated Values means.

Salem 5,265 Posting Sage

Read Me
You'll also need to set the PATH environment variable as well, so you can run the compiler from any directory and just bcc32\bin

Also, you should begin by creating say c:\projects which will contain all your code projects. Don't be tempted to try and develop code within the compiler installation directory structure.

Salem 5,265 Posting Sage

Well iostream.h isn't the standard name (it was in the old days, but not anymore).

Try

#include <iostream>
using namespace std;

Oh, and main returns int, not void.

Salem 5,265 Posting Sage

> getch() is executed before the file is displayed.!
> whats wrong?
The problem is is that you're mixing methods of input and output.

getch() being a low-level, compiler specific function is likely to bypass all the higher level (and probably buffered) functions.

What's worse is that getch() is horribly obsolete to start with, even in C programs, never mind C++ programs.

If you really need to pause, then you need to use a cin method to do the pausing.

Salem 5,265 Posting Sage

> I was just wondering if the math library is the only library I had to add to the
> Command line.
It's the only one of the standard header files you can include.
But if you include other non-standard headers, you'll need to link with other non-standard libraries as well.

Salem 5,265 Posting Sage

> IDD_PLAYERCOUNT DIALOG, 0, 0, 145, 60
I'm not that familiar with .rc syntax, but shouldn't there be a comma between DIALOG and the zero (shown in red)?

Salem 5,265 Posting Sage

> the compiler just hangs there without any response.
The compiler is all done if you've got an a.out file. If that isn't responding, it can only be your source code which is at fault. You need to post some for further enlightenment.

Salem 5,265 Posting Sage

gcc -E file.c > file.i Arrange for the offending file to be compiled like that. What you'll see in the .i file is your source code AFTER the pre-processor has done it's work. For one thing, it will be much longer because all the include files will be expanded. Another is all #defines will have been expanded.

You may find that you have something like 3 = DialogBox(g_hInst,MAKEINTRESOURCE(IDD_PLAYERCOUNT), hwnd, DlgProc); which would indicate that the variable name you're interested in is somehow a macro. It might not help that much, but seeing exactly what the compiler sees is a start. (NumOfPlayers) = DialogBox(g_hInst,MAKEINTRESOURCE(IDD_PLAYERCOUNT), hwnd, DlgProc); Should prevent the macro being expanded, if indeed it is a macro.

Salem 5,265 Posting Sage

Yes, fout << field << "," << anotherField << endl; So rather than using "\t" , use "," . It's that simple.

Salem 5,265 Posting Sage

> now what about reading and writing in a excel file(.cvs)
The same as you would for any other text file.

Salem 5,265 Posting Sage

http://en.wikipedia.org/wiki/Decompiler
Decompilation is like trying to get flour and eggs back from your cake.

Getting "something" which might compile is fairly do-able, but the results are only something a compiler could love. It will in no way resemble the source code which was originally compiled.

For example, a for loop and a while loop in C are essentially the same thing, and easily interchangeable in most circumstances. Which you might get is a toss of the coin, or you just might end up with a handful of goto's instead.

Salem 5,265 Posting Sage

.xls files are a proprietary (that's secret) format of microsoft.

For something portable, the best is "Comma Separated Values", or CSV.

So you would have say
1,2,3
hello,world
"and now, the news","for today"

If you save this text file with the extension .csv, then excel should be able to read it just fine.

Salem 5,265 Posting Sage

How about checking all the dumb stuff, like
- speakers not switched on
- speaker volume down low
- MIDI device not enabled
- MIDI device on mute

> Believe me, that's not a problem. Before, it worked without a switch at all.
Funny, sloppy or non-existent error checking is always a problem on the message boards.
Success yesterday doesn't count for much.
Success for other people doesn't count for much.

After some digging...
http://www.borg.com/~jglatt/tech/lowmidi.htm
Those examples seem to work, even when adapted into your code.

Salem 5,265 Posting Sage

its a joke right?

No it isn't.
http://c-faq.com/ansi/voidmain.html

If you ever get to the point of writing useful programs, don't screw up by writing void main and returning garbage to your users. I've been on the receiving end of such sloppy coding, and it's distinctly not funny.

Salem 5,265 Posting Sage

1. Your printf() statements in your switches need to have a trailing \n (or a call to fflush(stdout) ) to guarantee being able to see them.
2. You should really have a default case in your switch, to catch all other possible errors.

Salem 5,265 Posting Sage

> also please tell me which of the comments I should remove
All of them?

Example: else if(in[i]=='.') //if '.' is encountered How is that comment adding anything to the understanding? Comments which essentially repeat the syntax of the language don't add anything. Anyone reading the code could write those comments, but it wouldn't help understand what was going on, or why.

If you're implementing a published algorithm, then I'd expect to see references.
Things like "how" it does it, "why" it's needed are also useful things to know.

Narue's post #9 is pretty much what I'd go for, though I'd personally make the function header comments Doxygen compatible.

The /********** comments for breaking up the sections of the module are good, but just too long for this forum.

Salem 5,265 Posting Sage

> for (int i = 1; i <= numberOfVerticies; i++)
Arrays, including those you allocate, start at 0, not 1.
All your examples run off the end, and no doubt end up corrupting something else.

It should be for (int i = 0; i < numberOfVerticies; i++) In your face constructor,
> points = new int[10];
This is inconsistent with the value you've assigned for numberOfPoints.

Salem 5,265 Posting Sage

> Say every 5 miliseconds.
Does your monitor refresh at 200Hz ?

If there is no way for you to observe the effects of such a high resolution event, then what would be the point of trying it?

Besides, once you get below the normal scheduling frequency of the OS (which is usually 10ms or 20ms IIRC), then accurate timings in user code become pretty tricky.

Oh, and main returns int, not void.

Salem 5,265 Posting Sage

kbhit() is an old DOS function which detects when a key is pressed in a DOS environment.

You can write something which works the same in a win32 console, using the win32 console API

Salem 5,265 Posting Sage

Also learn how to indent your code. It's much easier to follow the logic of your program that way (for you and for us).

Salem 5,265 Posting Sage

Goto http://sourceforge.net
Type "Intrusion AND Detection AND System" into the search box, and click "search".

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

Your compiler itself is a DOS program.
Why would it know anything about how XP schedules programs?

As far as it is concerned, it has the entire machine to itself, so it's just going to grab all the CPU time that the virtual machine is willing to let it have. As a result, your system runs hot because the code is too stupid to run otherwise.

Salem 5,265 Posting Sage

You don't need threads, just the ability to read user input without blocking.

do {
  if ( keypressed() ) {
    key = readKey();
    handleKey(key);
  }
  moveFishes();
  refreshScreen();
} while ( numFishes > 0 );
Salem 5,265 Posting Sage

For sure you need a compiler which actually matches your OS, and doesn't just live inside the DOS emulation layer of your OS.

> I have Intel Core 2 Quad Q6600 2.4 Ghz processor
Yes, and despite all that, all that your programs will ever see of that machine is 1 core and 640K of memory. In what way do you regard this as being cost-effective use of the hardware you've purchased?

Step 1 - buy Ferrari.
Step 2 - replace engine with elastic bands.
Step 3 - complain on a forum about friction burns and why it doesn't go very far or very fast.

Here are some places to find out about new compilers.
http://www.thefreecountry.com/compilers/cpp.shtml
http://www.codeblocks.org/downloads.shtml

Salem 5,265 Posting Sage

Use strcpy() to copy the string.

Salem 5,265 Posting Sage

> In IE7 under the tools menu, there is an option to turn the popup blocker on or off.
Windows has this massive global variable called the registry.

> Would a text file be the most professional way to save the settings for an executable?
In the absence of compelling alternative requirements, there's no need to make settings unreadable by using some proprietary encoding format. Even Microsoft is coming around to the idea that what users really like is nice open standards for storing THEIR data, not some proprietary binary format which changes every couple of years and renders their precious data obsolete (and unsupported).

Salem 5,265 Posting Sage

All of those things will not stop the determined (or the incompetent) from modifying the file.

What's wrong with a nice simple text file, with a banner at the top which reads something like
# This file is auto-generated. Any changes you make could be lost
# or cause the programs to fail in unexpected ways.

It seems to work for a lot of other programs.

Salem 5,265 Posting Sage

Yes, you seem to be declaring lots of variables of the right type (as far as the called functions are concerned), but you've missed the point that all those pointers (the LP... variables) all need to point to somewhere.

dubeyprateek has already pointed those out.

What you also need to do is stop lying to the routines about how much memory they're allowed to use. ReadFile(hfile,lpBuffer,Mylength+1,&dwRead,NULL); You allocated Mylength, so say Mylength, not Mylength+1.
Functions are only safe if you're honest about the size they're allowed to work with.

Salem 5,265 Posting Sage

Of course posting actual code rather than just describing it would really help.

Salem 5,265 Posting Sage

Can you do my homework for me?

Salem 5,265 Posting Sage

OK, getting bored of you saying "it doesn't work" and you NOT posting the code.
Since I'm not interested in playing 20 questions just to figure out which of many 1000's of possible mistakes you might have made, I'm done here.

Salem 5,265 Posting Sage

You have to change the signature of the compare function, to expect pointers to two character pointers, not pointers to two character arrays.

Ancient Dragon commented: Your right -- thanks +20
Salem 5,265 Posting Sage

Create a small command (or batch) file, which reads as follows

@echo off
set TMP=C:\temp
start C:\Dev-Cpp\devcpp.exe

Change paths to suit.

Your default environment sets TMP and TEMP to point to a directory in your local settings. But you can reassign them to be whatever you want on a per process basis.