i've got an assignment for college that utilises a static data structure, specificaly a table structure
it will have a name, a credit limit and a refNumber(unique no.)

in my text book (which is written for pascal :( ) it says that when i delete a section of my table i should move the other data up to sort of fill in the gaps, but if its a static data structure, shouldn't the gaps stay and be filled when new data is added??

it also has a primitive operation called resetTable? which will reset the position back to the start of the table, i can understand why this is required at all

One extra check for each time you want to access any array element now, instead of just checking to see if the element you're accessing is higher than the total count or what not.

Quzah.

11-17-2001

Garfield

>> int main(void) <<

First of all, you should be doing 'int main()' for your definition of main.

>> table dataTable[MAX];//max is defined as 10 <<

Secondly, your declaration is a little off. It should be:

Code:

struct table dataTable[MAX];

But besides that, your code looks fine.

--Garfield

11-17-2001

Garfield

Arg!!! quzah and QuestionC got to it before me. Sorry for the clutter.

11-17-2001

quzah

Hehe. We all raced to reply apparently!

Quote:

>> int main(void) <<

First of all, you should be doing 'int main()' for your definition of main.

No. This is wrong. If you fail to provide the values, your compiler will default values for you. It's always better to indicate what you want than to rely on your compiler to provide defaults.

Additionally, this is not Java, so "myfunction(void)" isn't considered wrong. (I believe Java dislikes you to use the keyword "void" in method parameters.)

Quzah.

11-17-2001

Garfield

Unless you use #pragma, the program will start with main and I don't see the reason for parameter passing in main.

--Garfield

11-17-2001

korbitz

thanx for the quick reply guys

thats what i thought was the correct way, but wont that approach not make the table a static structure anymore, i get confused with the static/dynamic scenario

on the int main(void) flame, hehe blame my c teacher

on the struct correction, do you really need to place struct in front of it, i have a working program using a vector structure and i aint used struct at all except for setting up the structure itself

11-17-2001

QuestionC

Parameter passing in main just to make it explicit that you don't want anything. I'm sure there's somerule out there deciding what is and isn't legal for main declaration, but for all purposes,
int main (void)
is just documenting that you're not wanting to use any command line arguments. And whether one thinks it makes sense or not, it certainly is legal.

11-17-2001

Garfield

Yeah, I'm pretty sure you need the 'struct' keyword. If you just wanted to use 'table' as the specifier, then your struct would have to be set up like this:

Code:

struct {
/* struct members */
} table;

Then you can just write:

Code:

table tblVar;

Whatever you choose.

--Garfield

11-17-2001

Garfield

>> it certainly is legal. <<

I respect your answer, but just because something is legal, doesn't make it good practice. And not just in programming.

--Garfield

11-17-2001

QuestionC

I'm pretty sure it will make a static dtat structure actually. It's static because it occupies a constant amount of memory. It's not really a well defined term, but the implementation that you seem to describe follows what we suggested.

11-17-2001

quzah

>>> it certainly is legal. <<
>
>I respect your answer, but just because something is legal,
> doesn't make it good practice. And not just in programming.
>
>--Garfield

I fail to see why you are so hung up on this. In your opinion, why
is 'int main()' better than 'int main( void )'? Additionally, explain
then why this:

int myfunction()

is better than:

int myfunction(void)

It is always better to implicitly state what you mean, rather than
to have it left up to un-documented compiler defaults. (When I
say 'un-documented', I mean to say, that by glancing at the code
you know for a fact that '(void)' means it is guarinteed to have
no arguments.

If you say 'int main()', what defaults does it use? I can venture a
guess and say it's the same thing as 'void', but what if it isn't?
What if instead, it defaults to:

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

Not that it really should make any difference, if you aren't using
variables named that, but still, why is it "wrong" to be specific?

Quzah.

11-18-2001

Garfield

>> why is it "wrong" to be specific? <<

I didn't say it was wrong, now you're twisting my words. I said that it is not always good practice. I guess I can see your argument here.