-1

My code ( gist link )

//pre-processor directives
#include <stdio.h>
#include <math.h>

//Main function
int main() {
    int month, day, year, lowest_temp, highest_temp;
    float temp;
    char fname[30];

    FILE * ifp;

    printf("Tell me about your dragon's preferred temperature for flying: What is the coldest temperature they can fly in?\n");
    scanf("%d", lowest_temp);
    printf("What is the hottest temperature they can fly in?\n");
    scanf("%d", highest_temp);
    printf("Please enter the name of the weather data file for Dragon Island.\n");
    scanf("%s", fname);

    ifp = fopen(fname, "r");
    fscanf(ifp, "%d %d %d %f, &month &day &year &temp");

    printf("%d %d %d %f, &month &day &year &temp");

    return 0;

}

Crashes after first scanf no errors

If you can tell me what the error is I'd appreciate it. Also if you can help me with the next steps in my problem that would be awesome as well.

My assignment https://gist.github.com/anonymous/e9292f14b2f8f71501ea/88e9e980632871f1f1dedf7589bb518f1bba43e8

amdixon
  • 3,814
  • 8
  • 25
  • 34
tonomon
  • 1
  • 4
  • Possible duplicate of [Simple C scanf does not work?](http://stackoverflow.com/questions/3744776/simple-c-scanf-does-not-work) – lxx Oct 18 '15 at 03:24

1 Answers1

3
 scanf("%d", lowest_temp); 
 ...
 scanf("%d", highest_temp); 

%d require address of int argument you pass it just int variable . Pass their address -

scanf("%d",&lowest_temp); 
...
scanf("%d",&highest_temp); 

And these both statements-

fscanf(ifp, "%d %d %d %f, &month &day &year &temp");
printf("%d %d %d %f, &month &day &year &temp");   

should be-

fscanf(ifp, "%d %d %d %f", &month &day &year &temp);
printf("%d %d %d %f", month ,day,year ,temp);  
ameyCU
  • 16,489
  • 2
  • 26
  • 41