I have been working on this code for quite a while and have not been able to figure it out. I looked online and through the forums and could not find something that showed how to fix it.
This program takes in the julian date ie. 12df234(first two # are year, last 3 are date) and separates the numbers from the letters.
When i try to compile using gcc i get the warning
In function âextract_julianâ:
warning: passing argument 1 of âsscanfâ makes pointer from integer without a cast
/usr/include/stdio.h:430: note: expected âconst char * __restrict__â but argument is
is of type âcharâ
And when i run the program i get "segmentation fault"
This is my code
#include <stdio.h>
//function prototypes
void read_code(char *julian_date);
void extract_julian(int *day, int *year,char *julian_date);
int main()
char julian_date[7]; /* julian date consists of 7 characters*/
int day=0;
int year=0;
read_code(julian_date);
extract_julian(&day,&year,julian_date);
printf("this is day %d\n",day);
printf("this is year %d\n",year);
return 0;
}
void read_code(char *julian_date)/*this function is for input*/
{
printf("input the julian date.\n");
scanf("%s",julian_date);
}
void extract_julian(int *day,int *year,char *julian_date)/*this function extracts the numbers from the julian date*/
{
sscanf(julian_date,"%d",&*year); /* makes the first 2 numbers equal to year*/
sscanf(julian_date[4],"%d",&*day); /*makes last 3 equal to date*/
}
This is my first post so i am not sure if i used code tags right. Sorry if i didnt