Jump to content


invalid type argument of ‘unary *’


8 replies to this topic

#1 verdas87

    New Member

  • Members
  • Pip
  • 2 posts

Posted 03 December 2007 - 10:11 PM

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;
        }

}


#2 z80

    Valued Member

  • Members
  • PipPipPip
  • 104 posts

Posted 03 December 2007 - 10:25 PM

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...

#3 verdas87

    New Member

  • Members
  • Pip
  • 2 posts

Posted 03 December 2007 - 10:39 PM

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"

#4 Wernaeh

    Senior Member

  • Members
  • PipPipPipPip
  • 368 posts

Posted 03 December 2007 - 11:01 PM

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

Cheers,
- Wernaeh
Some call me mathematician, some just call me computer guy. Yet, I prefer the term professional weirdo :)

#5 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationBellevue, WA

Posted 03 December 2007 - 11:34 PM

BTW, verdas87, please use the [code][/code] tags to post code snippets in future. I added them for you, this time.
reedbeta.com - developer blog, OpenGL demos, and other projects

#6 zdax

    New Member

  • Validating
  • PipPip
  • 10 posts

Posted 04 December 2007 - 06:07 AM

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.

#7 .oisyn

    DevMaster Staff

  • Moderators
  • 1842 posts

Posted 04 December 2007 - 10:13 AM

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
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.

#8 poita

    Senior Member

  • Members
  • PipPipPipPip
  • 322 posts

Posted 05 December 2007 - 02:55 PM

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

#9 SmokingRope

    Valued Member

  • Members
  • PipPipPip
  • 210 posts

Posted 20 December 2007 - 02:47 PM

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;
}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users