Solved

syntax

Posted on 2000-05-01
1
182 Views
Last Modified: 2010-04-15
I get this error...

cc: Warning: numday.c, line 33: In this statement, "*total" of type "int", is be
ing converted to "pointer to int".
                        *total=31+numday(month-1, day, *total);
----------------------------------^
cc: Warning: numday.c, line 35: In this statement, "*total" of type "int", is be
ing converted to "pointer to int".
                        *total=30+numday(month-1, day, *total);
----------------------------------^

With the problem in this part of the code...

int numday(int month, int day, int *total)
        {

        if(month==1)
                *total=day;
        else if(month==2)
                *total=28+day;
        else
                {
                if(month==3||month==5||month==7||month==8
                  ||month==10||month==12)
                        *total=31+numday(month-1, day, *total);
                else
                        *total=30+numday(month-1, day, *total);
                }

        }

void printresults(int total, int month, int day)
        {
        printf("%d/%d is day %d of the year.", month, day, total);
        }


int main(void)

        {
        int month, day, total;

        getdata(&month, &day);

        numday(month, day, &total);

        printresults(total, month, day);

        }                



0
Comment
Question by:SaraBiz
1 Comment
 
LVL 1

Accepted Solution

by:
jasonf earned 50 total points
ID: 2768149
In the recursive call to numday you are dereferencing total and passing its value.  Your function prototype, however, wants you to pass an address where the data resides.  In other words, don't dereference total in the argument list in the recursive calls to numday.  That should work.

Look at the error, then think about what it is saying...I will break it down for you.

The error is:
cc: Warning: numday.c, line 33: In this statement, "*total" of type "int", is being converted to "pointer to int".

The line of code where the error occurs:
*total=31+numday(month-1, day, *total);

The prototype for the function numday:
int numday(int month, int day, int *total)

What does *total refer to?  It is the value in the memory location addressed by the value of total.  That value happens to be an int.

Now look at the 3rd argument in the prototype for numday.  It is looking for a pointer to int, in other words an address.  When you look at the value stored at that address it has to be an int (hence 'pointer to int').  Do you now see why you are getting the error you are getting?

Hope this helps and hope my explanation clears up some of the confusion with passing pointers to functions and what the notation means.

Jason
0

Featured Post

Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now