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

Edited 3 Years Ago by pyTony: fixed formating

Welcome to the forum, Roflspanker! ;)

I believe I see the problem, but let me set it up in my compiler.

Your code tags were perfect - except one [ char got skipped, somehow.

The accuracy I doubt, but it fixes the compiler errors:

/* doesn't work, just removing some compiler errors */

#include <stdio.h>

//function prototypes
void read_code(char *julian_date);
void extract_julian(int *day1, int *year1,char *julian_date);

int main(){

char julian_date[8]; /* julian date consists of 7 characters - leave room for the '\0'*/
int day1=0;
int year1=0;

read_code(julian_date);
extract_julian(&day1,&year1,julian_date);

printf("this is day %d\n",day1);
printf("this is year %d\n",year1);
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 *day1,int *year1,char *julian_date)/*this function extracts the numbers from the julian date*/
{
sscanf(julian_date,"%d",year1); /* makes the first 2 numbers equal to year*/
sscanf(&julian_date[4],"%d",day1); /*makes last 3 equal to date*/
}

(click on the [CODE] icon one time, and paste in the code)

Edited 3 Years Ago by pyTony: fixed formating

This question has already been answered. Start a new discussion instead.