Because the idea is to compile your .c / .cpp files, and include header files. It's what I like to call "bad form". It's ugly.

Quzah.

06-28-2004

Prelude

>anybody care to tell me why including .c files is a bad idea?
.c files routinely define things, and multiple definitions are illegal. Including a .c file will probably work if you only do so once and don't define any names that it defines, but doing so is tricky and error prone and considered very bad form.

06-28-2004

Prelude

>except if you place your code inside #ifndef right?
That's akin to putting a Band-Aid over a gunshot wound. It might work, but is it really addressing the right problem?

06-29-2004

Siggy

Thank you guys. I understand what went wrong. I really appreciate all of the help and when i code some more I'll put it up if i have any problems. One problem im havin right now is this. Can if/else statements handle things such as names.

example:
If I wanted to code something that asked for somones name and have it check whether it registers with the program or not. If it does register u can continue, otherwise the program ends. I tried writing one of these but I wasnt able to get it to work at all. So I was wondering if if/else was the right thing to use. Thanks!

06-30-2004

quzah

Quote:

Originally Posted by XSquared

Put the code of the e() function above main(), or use a prototype above main:

Code:

int e();

They could have also put the prototype in main.

Quzah.

06-30-2004

RealityFusion

Quote:

Originally Posted by Siggy

Can if/else statements handle things such as names.

example:
If I wanted to code something that asked for somones name and have it check whether it registers with the program or not. If it does register u can continue, otherwise the program ends. I tried writing one of these but I wasnt able to get it to work at all. So I was wondering if if/else was the right thing to use. Thanks!

A Switch statement would be a lot better function for you to use for this task.

The problem with the above-marked line is that you are not comparing the content of 'InputName' with the string "Bennyandthejets". You are actually comparing the location of each element. They will never be in the same location, so the code will output "I don't know you". In order to compare the elements correctly, you need the function lstrcmpi(). It compares two strings and returns 0 if they are the same. So, this is how you rewrite the above code:

So a simple way to complete your problem would be to compare the inputted string with a number of constant strings like so:

Code:

if (lstrcmpi(InputName,"benny")==0)
GoIntoProgram();
if (lstrcmpi(InputName,"siggy")==0)
GoIntoProgram();

ExitProgram();

So the name entered must be 'benny' or 'siggy' for the program to continue. That is a simple way of doing it. There are nicer and more complicated ways of doing it too, but you'd best save that for later.

Quote:

A Switch statement would be a lot better function for you to use for this task.

What do you base this statement on? Strings are messy with switch statements. This is how I do it:

>In order to compare the elements correctly, you need the function lstrcmpi().
This isn't a standard function. As such, not all implementations are guaranteed to have it, and even if the OP's implementation does have it, the code won't be portable. On top of that, lstrcmpi has different results than might be expected due to special treatment of certain nonalphabetic characters. Better to either use strcmp, strncmp, or use the C++ string class (preferable) for now. :)