invalid type argument of ‘unary *’

148659a3cd4fc5366fccb0f9003679d3
0
verdas87 101 Dec 03, 2007 at 22:11

Im going to apologize in advance because Im really new to this stuff and Im not sure how bad off I am. I need to use pointers and functions and translate a user imput up to 365 into Julian date (hence 1 = jan 1st and 365 = dec 31)
right now i get the error (invalid type argument of ‘unary *’)
could anyone tell me how to fix it and what else might be wrong.
Im not real comfortable with pointers so im guessing somethings wrong there too. Any help would be appreciated.

#include <stdio.h>
#include <stdlib.h>

void convert_jdate(int julian_date, int *month, int *day) {

        if (julian_date <= 31) {
        int month = 1;
        int day = julian_date;
}

        else if (julian_date <= 59) {
        int month_name = 2;
        int day = julian_date-31;
}

        else if (julian_date <= 90) {
        int month_name = 3;
        int day = julian_date-59;
}

        else if (julian_date <= 120) {
        int month_name = 4;
        int day = julian_date-90;
}

        else if (julian_date <= 151) {
        int month_name = 5;
        int day = julian_date-120;
}

        else if (julian_date <= 181) {
        int month_name = 6;
        int day = julian_date-151;
}

        else if (julian_date <= 212) {
        int month_name = 7;
        int day = julian_date-181;
}

        else if (julian_date <= 243) {
        int month_name = 8;
        int day = julian_date-212;
}

        else if (julian_date <= 273) {
        int month_name = 9;
        int day = julian_date-243;
}

        else if (julian_date <= 304) {
        int month_name = 10;
        int day = julian_date-273;
                                                                                                                                            }

        else if (julian_date <= 334) {
        int month_name = 11;
        int day = julian_date-304;
}

        else if (julian_date <= 365) {
        int month_name = 12;
        int day = julian_date-334;
}




return;

int main(void) {

        int jdate;
        int month;
        int day;
        char* month_name[12] = {
                "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
        };

        printf("enter Julian date (a number between 1 and 365)\n");
        if (scanf("%d", &jdate) != 1) {
                printf("not a number\n");
                return EXIT_FAILURE;
        }
        else if ((jdate < 1) || (jdate > 365)) {
                printf("not between 1 and 365\n");
                return EXIT_FAILURE;
        }
        else {
                convert_jdate(jdate, *month, *day);

                printf("Julian date %d is %s %d\n", jdate, month_name[month-1], day);

                return EXIT_SUCCESS;
        }

}

8 Replies

Please log in or register to post a reply.

254754b37f468a2926bffcd83bbbf1fa
0
z80 101 Dec 03, 2007 at 22:25

Not that I checked everything thru for errors and mistakes but you probably wanna do

convert_jdate(jdate, &month, &day);

instead of

convert_jdate(jdate, *month, *day);

in order to pass pointers (hence the address-of operator &) to the ints…

148659a3cd4fc5366fccb0f9003679d3
0
verdas87 101 Dec 03, 2007 at 22:39

yep that cut that error out, kinda forgot about that. thanks.

I don’t want to abuse the forum asking stupid questions but is there something thats supposed to go near the end that im missing? the only error I get now is “expected declaration or statement at end of input”

B7568a7d781a2ebebe3fa176215ae667
0
Wernaeh 101 Dec 03, 2007 at 23:01

The convert_jdate call is missing its closing bracket, right after the return statement.

Cheers,
- Wernaeh

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Dec 03, 2007 at 23:34

BTW, verdas87, please use the [/code[b][/b]] tags to post code snippets in future. I added them for you, this time. [code][/code**] tags to post code snippets in future. I added them for you, this time.

27b2b627b23d6e7f4c8929d0ee650c8c
0
zdax 101 Dec 04, 2007 at 06:07

Also you are redeclaring the month and day parameters in your function.
So instead of

int month = 1;
int day = julian_date;

try

*month = 1;
*day = julian_date;

Same applies to every if/else branch, of course.

340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Dec 04, 2007 at 10:13

Also, I would suggest storing the months lengths in an array and use a simple loop to lookup the date, instead of having 12 if/elseif statements

36b416ed76cbaff49c8f6b7511458883
0
poita 101 Dec 05, 2007 at 14:55

Also, in addition to oisyn’s suggestion, this is a perfect scenario for testing your dynamic programming skills. :)

860fe478a2545d6c07b88c759292499e
0
SmokingRope 101 Dec 20, 2007 at 14:47

Like this? :lol:

void convert_jdate(int julian_date, int *month, int *day) {
        int l_lookup[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        for( *month=0 ; *month < 12 ; ++*month ) {
            *day = l_lookup[*month];
            if( *day < julian_date ) julian_date -= *day;
            else break;
        }
        *day = julian_date;
        ++*month;
}