Re: First program in C - what is going on with function returns?
- From: Kelsey Bjarnason <kbjarnason@xxxxxxxxx>
- Date: Sun, 30 Apr 2006 10:07:44 GMT
[snips]
On Sat, 29 Apr 2006 23:52:57 -0700, ben.carbery wrote:
Full code below. By the way any other tips on my code would be welcomed
and appreciated!
You said "full code" - but I don't see the proper includes here.
char datestring[80];
/* dim is 'days in month'*/
int dim;
speakdate(int d, int m, int y)
What type is being returned? If you meant "nothing", specify void.
strcpy(datestring,stdate);
strcat(datestring,stmonth);
At the end of the function, the global datestring has a date. So far so
good.
int countdays(int bd, int bm, int by, int cd, int cm, int cy) {
int month,year;
int daysalive = 0;
/* count the days in whole years */
for (year=by+1;year<cy;year=++year) {
You probably don't want year=++year, but simply ++year
if (fmod(year,4)==0) {
At a guess, you simply want the modulus operand - % - here.
main(void)
int main(void)
{
int bdate,bmonth,byear;
printf ("Please enter your birth date (d/m/yyyy):\n"); scanf
("%d/%d/%d",&bdate,&bmonth,&byear);
printf ("Your date of birth is %s\n\n",speakdate(bdate,bmonth,byear));
speakdate(), as written, returns nothing, so treating it as if it does is
an error. That you get any output at all is simply a matter of accident.
printf ("Congratulations! You were born a total of %d days
ago.\n",countdays(bdate,bmonth,byear,cdate,cmonth,cyear));
[/code]
No close brace, no return. Despite the claim of "full code below",
there's no way this could be the full code, as it cannot compile.
That said, you should also turn your compiler's warning level to maximum,
and pay attention to the warnings.
.
- Follow-Ups:
- Re: First program in C - what is going on with function returns?
- From: ben . carbery
- Re: First program in C - what is going on with function returns?
- References:
- First program in C - what is going on with function returns?
- From: ben . carbery
- First program in C - what is going on with function returns?
- Prev by Date: Re: Boost process and C
- Next by Date: Re: discussing C evolution
- Previous by thread: Re: First program in C - what is going on with function returns?
- Next by thread: Re: First program in C - what is going on with function returns?
- Index(es):
Relevant Pages
|
|