desperatelly need help, please respond 
Author Message
 desperatelly need help, please respond

i am trying to create a program which calculates taxes for 5 people based on
their marital statuas and their income. i ve basically completed this
program but because of some unknown to me reason the program doesnt work.
the problem occurs when i input invalid values eg letters instaead fo
numbers the program doesnt catch it. also even though loop goes up to five
the program refuses to go past two.

If anyone could PLEASE help me with this program io would be very greateful
to You. I am not trying to get you do my work for me I just need help
desperatelly. PLEASE someone help me with this
THANK YOU in advance for your replies
PAUL
====================================================================
/*Filename:tax604.c
 Program which calculates taxes paid for 5 people */
 #include<stdio.h>
 #include<ctype.h>

 void introduction();
 void information();
 int validation();
 void calculation();
 void output();

 int index, income[5], total_tax[5];
 char marital_stat[5], cincome[5];
 float tax_rate[5];

 void main()
 {
 introduction();
 information();
 calculation();
 output();
 }

 /*The following are functions used in this program*/
/*--------------------------------------------------------------------------
--*/
 void introduction()
 { printf("\t\t\t\tTAX PROGRAM\n\t\t\t   \n\n");
 printf("\t\t\t\tINSTRUCTIONS:\n");
 printf("\t\t     1.ENTER MARITAL STATUS OF A PERSON (m/s).\n");
 printf("\t\t     2.ENTER ANNUAL SALARY FOR A PERSON (must be numeric).\n");
 printf("\t\t\t   3.REPEAT 5 TIMES.\n\n");
 return;
 }
/*--------------------------------------------------------------------------
--*/
void information()
 {int agoodnum=0;
 for (index=0; index<=4; index++)
   {
   printf("\rplease enter the marital status of person # ");
   printf("%d -->", index+1);
   scanf(" %c", &marital_stat[index]);
   fflush(stdin);
   marital_stat[index]=tolower(marital_stat[index]);

     while((marital_stat[index]!='s')&&(marital_stat[index]!='m'))
      {printf("error: invalid input\n");
     printf("\rplease enter the marital status of person # ");
     printf("%d -->", index+1);
     scanf(" %c", &marital_stat[index]);
     fflush(stdin);
      }
  do
  {
   printf("\rplease enter income of person # ");
   printf("%d ==>", index+1);
   gets(cincome);
   agoodnum = validation();
  }

  while(! agoodnum);
  }
  return;
  }
/*=======================================================================*/
int validation()
{ int goodnum = 1;
 for(index=0; cincome[index]='\0'; index++)
 {
   do
  {printf("\rerror:not a number");
   goodnum=0;
   break;
   }
   while(! isdigit(cincome[index]));
   }
   return goodnum;
   }
/*======================================================================*/
void calculation()
{   for (index=0; index<=4; index++)
{
 switch (marital_stat[index])
    {
    case('m'):
     {

     if(income[index]>= 5000)
      {tax_rate[index] = .12;}
     else
      { tax_rate[index]=0.00;}
     break;
     }
     case('s'):
     {
     if(income[index]>=5000)
     { tax_rate[index]= .15;}
     else
     {tax_rate[index]= .10;}
     break;
     }}
   }
 total_tax[index]=income[index]*tax_rate[index];
   return;

Quote:
}

/*=====================================================================*/
/*output*/
void output()
{ printf("\t\t\t\tINCOME TAX REPORT");
  printf("\nPerson#       Salary        Mar-Stat       Tax Rate
Total-Tax");

ntf("\r-------       ------        --------       --------     ---------");

  for ( index=0; index<=4; index++)
  {
  printf("\r %d       |     %d       |       %c     |    .2%f
..2%f\n",
  index+1, income[index], marital_stat[index], tax_rate[index],
total_tax[index]);
  }
  return;
  }
--
http://www.*-*-*.com/

--



Mon, 31 Dec 2001 03:00:00 GMT  
 desperatelly need help, please respond
you're using a variable named "index" for loop control in both the
information() function and the validation() function.

unfortunately, index is a global variable, which means the second loop
is screwing up the count for the first loop.

make index a local variable in each function.

also, don't use fflush(stdin).  fflush() is only defined to work
on _output_ streams.

---
John Gordon                  "No Silicon Heaven?  Preposterous!  Where would

--



Tue, 01 Jan 2002 03:00:00 GMT  
 desperatelly need help, please respond
Quote:

>i am trying to create a program which calculates taxes for 5 people based on
>their marital statuas and their income. i ve basically completed this
>program but because of some unknown to me reason the program doesnt work.
>the problem occurs when i input invalid values eg letters instaead fo
>numbers the program doesnt catch it. also even though loop goes up to five
>the program refuses to go past two.

<rest snipped>

Your problem is that you use scanf() and gets() for user input. Neither
of those functions is particularly good for user input; use fgets()
instead. Also take the time to read the comp.lang.c FAQ; it will address
many issues like the usage of void main() and fflush(stdin), which are
both illegal.

Gergo

--
'Tis the dream of each programmer,
Before his life is done,
To write three lines of APL,
And make the damn things run.

GU d- s:+ a--- C++>$ UL+++ P>++ L+++ E>++ W+ N++ o? K- w--- !O !M !V
PS+ PE+ Y+ PGP+ t* 5+ X- R>+ tv++ b+>+++ DI+ D+ G>++ e* h! !r !y+
--



Tue, 01 Jan 2002 03:00:00 GMT  
 desperatelly need help, please respond

Quote:

>i am trying to create a program which calculates taxes for 5 people based on
>their marital statuas and their income. i ve basically completed this
>program but because of some unknown to me reason the program doesnt work.

<snip>

Didn't I reply to this two days ago?

I see that you still have largely the same uncorrected errors that you
presented before.  There's also at least new one:

Original:

        main()                  /* Assumed int; unspecif. args */
        {
        }

New:

        void main()             /* Illegal void; unspecif. args */
        {
        }

Originally suggested:

        int main(void)  /* int type; no args */
        {
        }
--
Robert B. Clark
Visit ClarkWehyr Enterprises On-Line at http://www.iquest.net/~rclark/ClarkWehyr.html
.
--



Tue, 01 Jan 2002 03:00:00 GMT  
 desperatelly need help, please respond
In short:
Your using all goo-ball (I mean global) variables.

The variable 'index' is being changed in both information() and
validation() which is called from information.

Make it local.

I also suggest avoiding goo-ball variables if you can help it.

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
--



Tue, 01 Jan 2002 03:00:00 GMT  
 desperatelly need help, please respond

Line
    for(index=0; cincome[index]='\0'; index++)

is very suspicious.
That is the case, when a good compiler gives you a warning smth like
"suspicious assignment".
Look carefully
    cincome[index]='\0'   assigns zero to cincome[index] and then checks if
it's true. Since you just put zero in there you get "False" and therefore
you don't enter the loop.

    Your     int validation() always returns 1.

--



Tue, 01 Jan 2002 03:00:00 GMT  
 desperatelly need help, please respond


- snip -

Quote:
> If anyone could PLEASE help me with this program io would be very
greateful
> to You. I am not trying to get you do my work for me I just need help
> desperatelly. PLEASE someone help me with this
> THANK YOU in advance for your replies
> PAUL

Global variables are a very bad thing.
Your problem illustrates this.

First make index a local variable in each function
 which needs one for its for-loop.

Then clean-up the formatting of the code.  It is hard to read
and makes it easier to overlook errors.

There simply is no good reason to make main() return void.
Change it to return an int and make its last statement
return 0;
- snip -

--



Tue, 01 Jan 2002 03:00:00 GMT  
 desperatelly need help, please respond

Quote:

>i am trying to create a program which calculates taxes for 5 people based
on
>their marital statuas and their income. i ve basically completed this
>program but because of some unknown to me reason the program doesnt work.
>the problem occurs when i input invalid values eg letters instaead fo
>numbers the program doesnt catch it. also even though loop goes up to five
>the program refuses to go past two.

>If anyone could PLEASE help me with this program io would be very greateful
>to You. I am not trying to get you do my work for me I just need help
>desperatelly. PLEASE someone help me with this
>THANK YOU in advance for your replies
>PAUL
>====================================================================
>/*Filename:tax604.c
> Program which calculates taxes paid for 5 people */
> #include<stdio.h>
> #include<ctype.h>

> void introduction();

void introduction(void);

In C () means that you can pass anything as arguments. (void) means no
arguments. This is a difference with C++. Same for the next declarations and
all definitions.

Quote:
> void information();
> int validation();

bool validation();

Quote:
> void calculation();
> void output();

> int index, income[5], total_tax[5];
> char marital_stat[5], cincome[5];
> float tax_rate[5];

Why the 5 hardcoded? Use the following.

const int NPERSONS = 5;
const int MAXINPUT = 80;

int index, income[NPERSONS], total_tax[NPERSONS];
char marital_stat[NPERSONS], cincome[NPERSONS][MAXINPUT];
float tax_rate[NPERSONS];

That way you can change the number of persons safely by changing one line.
Of course, you have to use this constant in the rest of your program as
well.

Onother problem starts here. cincome is defined as an array of 5 chars. But
what you probably want here is an array of strings. There are lots of ways
to skin that cat, but for now do it as I showed here.

Quote:

> void main()

int main(void)

main returns an int, despite what some helpfiles/authors may say. Even if it
works on your compiler, int main() is the standard an it's a good habit to
get into (see the FAQ as well).

- Show quoted text -

Quote:
> {
> introduction();
> information();
> calculation();
> output();
> }

> /*The following are functions used in this program*/
>/*-------------------------------------------------------------------------
-
>--*/
> void introduction()
> { printf("\t\t\t\tTAX PROGRAM\n\t\t\t   \n\n");
> printf("\t\t\t\tINSTRUCTIONS:\n");
> printf("\t\t     1.ENTER MARITAL STATUS OF A PERSON (m/s).\n");
> printf("\t\t     2.ENTER ANNUAL SALARY FOR A PERSON (must be
numeric).\n");
> printf("\t\t\t   3.REPEAT 5 TIMES.\n\n");

You don't know the tabsize in advance, better to use spaces to line it out.

Quote:
> return;

Style issue, you don't need the return here. Most people find this bad
style.

Quote:
> }
>/*-------------------------------------------------------------------------
-
>--*/
>void information()
> {int agoodnum=0;

bool agoodnum = false;

Quote:
> for (index=0; index<=4; index++)

for (index=0; index<NPERSONS; index++)

Quote:
>   {
>   printf("\rplease enter the marital status of person # ");

Don't use \r, use \n. It is both non-standard and may not do what you want
on the next machine.

Quote:
>   printf("%d -->", index+1);

fflush(stdout);

Quote:
>   scanf(" %c", &marital_stat[index]);
>   fflush(stdin);

BAD! fflush(stdin) is undefined. Don't do it. A better way is to use fgets
to read a line (don't use gets!) and parse that line. See the FAQ for more
info.

Quote:
>   marital_stat[index]=tolower(marital_stat[index]);

>     while((marital_stat[index]!='s')&&(marital_stat[index]!='m'))
>      {printf("error: invalid input\n");
>     printf("\rplease enter the marital status of person # ");
>     printf("%d -->", index+1);

fflush(stdout);

Quote:
>     scanf(" %c", &marital_stat[index]);
>     fflush(stdin);
>      }
>  do
>  {
>   printf("\rplease enter income of person # ");
>   printf("%d ==>", index+1);
>   gets(cincome);

Don't use gets (see the FAQ), use fgets. But beside that, you are inputting
data in the global array cincome. Try this:

if (!fgets(cincome[index], MAXINPUT, stdin))
{
    perror("something bad happened");
    exit(EXIT_FAILURE);

Quote:
}
>   agoodnum = validation();
>  }

>  while(! agoodnum);
>  }
>  return;
>  }
>/*=======================================================================*/
>int validation()

bool validation(void)

Quote:
>{ int goodnum = 1;

delete this line.

Quote:
> for(index=0; cincome[index]='\0'; index++)

Here you{*filter*}up you global index variable. This is also absolutely not
what you want. Try this:

char *p = cincome[index];
while (*p)
{
    if (!isdigit(*p++))
        return false;

Quote:
}

return true;

or:
int i;
for (i=0; cincome[index][i] != '\0'; i++)
{
    if (!isdigit(cincome[index][i]))
        return false;

Quote:
}

return true;

Which does the same.

Quote:
> {
>   do
>  {printf("\rerror:not a number");
>   goodnum=0;
>   break;
>   }
>   while(! isdigit(cincome[index]));
>   }
>   return goodnum;
>   }
>/*======================================================================*/

I'll leave it at that, you'll be able to figure it out from here I hope.

Some random notes.

I hope that posting screwed up your indentation, otherwise, indent, indent,
indent.

Good excercise, get rid of the global variable index. Define it in
information() and pass it as a parameter to every function that needs it.

HTH,
Martijn
--
My reply-to address is intentionally set to /dev/null
reply to <newsgroupname> at greebo.orion in nl

--



Tue, 01 Jan 2002 03:00:00 GMT  
 desperatelly need help, please respond


Quote:
>i am trying to create a program which calculates taxes for 5 people based on
>their marital statuas and their income. i ve basically completed this
>program but because of some unknown to me reason the program doesnt work.
>the problem occurs when i input invalid values eg letters instaead fo
>numbers the program doesnt catch it. also even though loop goes up to five
>the program refuses to go past two.

>If anyone could PLEASE help me with this program io would be very greateful
>to You. I am not trying to get you do my work for me I just need help
>desperatelly. PLEASE someone help me with this
>THANK YOU in advance for your replies
>PAUL
>====================================================================
>/*Filename:tax604.c
> Program which calculates taxes paid for 5 people */
> #include<stdio.h>
> #include<ctype.h>

## the declarations below should have void as the parameter. However I
notice that you are using Global variables which in general is NOT a
good idea. It may be a good idea to sort out where you are passing the
information in your program and alter the functions accordingly.
Quote:
> void introduction();
> void information();
> int validation();
> void calculation();
> void output();

> int index, income[5], total_tax[5];
> char marital_stat[5], cincome[5];
> float tax_rate[5];

> void main()

## main ALWAYS returns int so
int main void

- Show quoted text -

Quote:
> {
> introduction();
> information();
> calculation();
> output();
return 0;
> }

> /*The following are functions used in this program*/
>/*--------------------------------------------------------------------------
>--*/
> void introduction()
> { printf("\t\t\t\tTAX PROGRAM\n\t\t\t   \n\n");
> printf("\t\t\t\tINSTRUCTIONS:\n");
> printf("\t\t     1.ENTER MARITAL STATUS OF A PERSON (m/s).\n");
> printf("\t\t     2.ENTER ANNUAL SALARY FOR A PERSON (must be numeric).\n");
> printf("\t\t\t   3.REPEAT 5 TIMES.\n\n");
> return;
> }
>/*--------------------------------------------------------------------------
>--*/
>void information()
> {int agoodnum=0;
> for (index=0; index<=4; index++)
>   {
>   printf("\rplease enter the marital status of person # ");
>   printf("%d -->", index+1);
>   scanf(" %c", &marital_stat[index]);

## scanf is not a good function for user input
Quote:
>   fflush(stdin);

## performing fflush on stdin is not defined.
Quote:
>   marital_stat[index]=tolower(marital_stat[index]);

>     while((marital_stat[index]!='s')&&(marital_stat[index]!='m'))
>      {printf("error: invalid input\n");
>     printf("\rplease enter the marital status of person # ");
>     printf("%d -->", index+1);
>     scanf(" %c", &marital_stat[index]);
>     fflush(stdin);

## see the comments above
Quote:
>      }
>  do
>  {
>   printf("\rplease enter income of person # ");
>   printf("%d ==>", index+1);
>   gets(cincome);

## gets is even worse than scanf in some peoples eyes.

- Show quoted text -

Quote:
>   agoodnum = validation();
>  }

>  while(! agoodnum);
>  }
>  return;
>  }
>/*=======================================================================*/
>int validation()
>{ int goodnum = 1;
> for(index=0; cincome[index]='\0'; index++)
##
> {
>   do
>  {printf("\rerror:not a number");
>   goodnum=0;
>   break;
>   }
>   while(! isdigit(cincome[index]));
>   }
>   return goodnum;
>   }
>/*======================================================================*/
>void calculation()
>{   for (index=0; index<=4; index++)

## most would use index < 5 in the above

- Show quoted text -

Quote:
>{
> switch (marital_stat[index])
>    {
>    case('m'):
>     {

>     if(income[index]>= 5000)
>      {tax_rate[index] = .12;}
>     else
>      { tax_rate[index]=0.00;}
>     break;
>     }
>     case('s'):
>     {
>     if(income[index]>=5000)
>     { tax_rate[index]= .15;}
>     else
>     {tax_rate[index]= .10;}
>     break;
>     }}
>   }

## your indenting style is somewhat strange to say the least.

- Show quoted text -

Quote:
> total_tax[index]=income[index]*tax_rate[index];
>   return;
>}
>/*=====================================================================*/
>/*output*/
>void output()
>{ printf("\t\t\t\tINCOME TAX REPORT");
>  printf("\nPerson#       Salary        Mar-Stat       Tax Rate
>Total-Tax");

>ntf("\r-------       ------        --------       --------     ---------");

>  for ( index=0; index<=4; index++)
>  {
>  printf("\r %d       |     %d       |       %c     |    .2%f
>..2%f\n",

## The width specifiers for the floating point variables is wrong.
## it should be %4.2f, I>E> the width value comes between the % and
## the f
Quote:
>  index+1, income[index], marital_stat[index], tax_rate[index],
>total_tax[index]);
>  }
>  return;
>  }
>--

Here is a rewritten version. It is not optimal but should help you.

/*Filename:tax604.c
 Program which calculates taxes paid for 5 people */
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>

struct persDets{
        char marital_stat;
        int income;
        float tax_rate;
        float total_tax;
        };
 void introduction(void);
 void information(struct persDets*);
 int validation(char*, int*);
 void calculation(struct persDets*);
 void output(struct persDets*);

#define QTY 5

int main(void)
{
        struct persDets group[QTY];

        introduction();
        information(group);
        calculation(group);
        output(group);
        return 0;

Quote:
}

 /*The following are functions used in this program*/
/*----------------------------------------------------------------------
*/
void introduction(void)
{
        printf("\t\t\t\tTAX PROGRAM\n\t\t\t\n\n");
        printf("\t\t\t\tINSTRUCTIONS:\n");
        printf("\t\t     1.ENTER MARITAL STATUS OF A PERSON (m/s).\n");
        printf("\t\t     2.ENTER ANNUAL SALARY FOR A PERSON (must be
numeric).\n");
        printf("\t\t\t   3.REPEAT 5 TIMES.\n\n");
        return;
Quote:
}

/*----------------------------------------------------------------------
-*/
void information(struct persDets group[])
{
        int agoodnum = 0;
        int i, val = 0;
        char income[10];
        char line[20];
        char status;
        char *p;

        for(i = 0; i < 5; ++i)
                group[i].marital_stat = '-';

        for (i=0; i < 5; ++i)
        {
                while((group[i].marital_stat!='s')&&(group[i].marital_st
at!='m'))
                {
                        printf("\rPlease enter the marital status of
person # ");
                        printf("%d -->", i+1);
                        fflush(stdout);
                        fgets(line, sizeof(line), stdin);
                        sscanf(line, "%c", &status);

                        group[i].marital_stat = tolower(status);
                }

                do
                {
                        printf("\rplease enter income of person # ");
                        printf("%d ==>", i+1);
                        fgets(line, sizeof(line), stdin);
                        sscanf(line, "%s", income);
                        if((p = strchr(income, '\n')) != NULL)
                                *p = '\0';
                        agoodnum = validation(income, &val);
                }while(!agoodnum);
                group[i].income = val;
        }
        return;

Quote:
}

/*======================================================================
=*/
int validation(char* income, int* value)
{
        char *p = income;

        while(*income != '\0')
        {
                if(!isdigit(*income))
                {
                        printf("\nerror:not a number\n");
                        return 0;
                }
                ++income;
        }
        *value = atoi(p);
        return 1;

Quote:
}

/*======================================================================
*/
void calculation(struct persDets group[])
{
        int i;

        for (i=0; i<5; i++)
        {
                switch (group[i].marital_stat)
                {
                        case 'm':
                        {
                                if(group[i].income >= 5000)
                                        group[i].tax_rate = .12;
                                else
                                        group[i].tax_rate = 0.00;
                                break;
                        }
                        case's':
                        {
                                if(group[i].income >= 5000)
                                        group[i].tax_rate= .15;
                                 else
                                        group[i].tax_rate = .10;
                                break;
                        }
                }
                group[i].total_tax =group[i].income * group[i].tax_rate;
        }
        return;

Quote:
}

/*=====================================================================*
/
/*output*/
void output(struct persDets group[])
{
        int i;

        printf("\t\t\t\tINCOME TAX REPORT\n");
        printf("Person#    Salary    Mar-Stat    Tax Rate Total-Tax\n");

        printf("-------    ------    --------    -------- ---------\n");

        for (i = 0; i < 5; i++)
        {
                printf(" %d     |    %d   |   %c     |    %4.2f Y
%4.2f\n",
                i+1, group[i].income, group[i].marital_stat,
group[i].tax_rate, group[i].total_tax);
        }
        return;

Quote:
}

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bob Wightman
--



Tue, 01 Jan 2002 03:00:00 GMT  
 desperatelly need help, please respond
I found this program very hard to read.  You need to
choose _one_ style for indenting and braces and use
it _consistently_.  People will be more willing to take
a look at your code and help you if you make the code
readable.  (I personally think two spaces is not enough
to make the indentation levels easy to track visually,
but that is a minor issue compared to the lack of
consistency.)

It would be better to prototype your functions, e.g.,
   void introduction(void);
rather than just declaring them, e.g.,
   void introduction();

It would seem that empty parentheses in a function
declaration would mean the function takes no
arguments, but for backward compatibilty with
older (before the ANSI C standard) versions of C,
it actually doesn't tell the compiler anything about
the arguments the function expects.

With full function prototypes, the compiler is more
likely to tell you if accidentally supply arguments to
a function that doesn't have any.  Making it easy
for the compiler to catch your mistakes for you is
always a good idea.

Your reliance on global variables rather than function
parameters to move information around the program is
a questionable design decision.  Since the program is
so small, and income[], total_tax[], marital_stat[], and
tax_rate[] are used in so many of the functions, it is
justifiable for those variables.

'index' should  _absolutely_  _not_  be a global variable.
A local 'index' should be declared separately in each
function that needs it.  The admonition to keep the use
of global variables to a minimum isn't some impractical
esthetic purism.  Most principles of good style aren't.
In this case, using local index variables would eliminate
a bug from your program.  information() calls validation()
from within a for loop that uses 'index'.  validation()
changes the value of 'index', thus screwing up the
subsequent operation of information().

The standard library function gets() should never be
used.  Use fgets() instead.  See the FAQ, question
12.23.  (Actually, you should probably read the whole
FAQ.  I've been programming in C for 14 years, and I
still review reference materials on it frequently.  Don't
be too proud or too lazy to study your primary tools!)

I think cincome needs to have more than 5 elements - that's
only enough room for a 4-digit number.

Using gets() with an input buffer that is too small even
for normal inputs is certain to cause problems.  gets()
is overwriting whatever is in memory after cincome[] -
probably some of your other variables, but it could be
anything.  Or it could also cause a memory protection
violation.

The character string you get for income (in cincome[])
never gets converted to an int and stored in income[].

The test in the for loop in validation(),
   cincome[index]='\0'
Needs to use the '==' operator, not the '=' operator.
This error causes validation() to approve anything you
give it.  I strongly urge you to to take the time to
understand why this is the case.  You'll learn a lot.
I'll get you started:
(1) In C, an assignment (like a = b) is an expression.
It has a value that can be used just like the value of
any other expression.
(2) The test in a for, while, do while, or if statement
is just an expression.  If the value of the test
expression is 0, one thing happens; if it's anything
other than 0, something else happens.
(3) Now, pretend you're the computer and execute
validation() step-by-step.  Don't think about what you
_meant_ validation() to do.  Look at what it actually
does.

There may be other problems that I didn't notice.
As I said at the beginning, the inconsistent
formatting makes it hard to tell what's going on.

-- Gary Culp
--



Fri, 04 Jan 2002 03:00:00 GMT  
 desperatelly need help, please respond
Fri, 16 Jul 1999 21:21:46 GMT,


Quote:
>         void main()             /* Illegal void; unspecif. args */
>         {
>         }

() in a function *definition* means zero arguments,
not unspecified, and is legal for main(); void (or
any other non-int) return type is (as you say) wrong.  

The tricky bit (which got me a while back) is that
int foo(void){ ... } counts as a prototype declaration
that requires subsequent (within the translation unit)
calls be checked and/or converted correctly; the (K&R1)
definition int foo() does not.  This is rarely an issue
with main(), since recursive calls to main are rare
outside IOCCC programs, but it may matter for other
functions, and it's best to be consistent.  

See also thread now running in comp.lang.c (only)
on "random number generation" where this is being
discussed at much greater length.  

(CCed) david.thompson at but not for trintech.com
--



Sat, 05 Jan 2002 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. desperatelly need help, please respond

2. PLEASE RESPOND: Program Help (fwd)

3. NEED HELP WITH PRITING AN ARRAY, PLEASE PLEASE HELP

4. help: Guru needed please please please

5. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

6. Please help!!!!Please help!!!!Please help!!!!

7. need help please please setting registry value

8. Help C newbie need help please

9. test message please don't respond

10. Help C newbie need help please

11. I really need some help with C graphics PLEASE HELP

12. Need help on this programming problem ( PLEASE HELP!!!)

 

 
Powered by phpBB® Forum Software