SegFault after scanf?

后端 未结 4 536
南笙
南笙 2020-11-28 17:04
#include 
#define TimeConverter 60
#define TempFormula time * time * 4 / time + 2 - 20

double HoursMinToTime(int hour, int min);

double Temperature(         


        
相关标签:
4条回答
  • 2020-11-28 17:14

    scanf requires the addresses of the variables to be passed to it. Replace your scanf by

    scanf("%d %d",&hour,&min);
    

    You should be good to go.

    0 讨论(0)
  • 2020-11-28 17:14

    You need to pass the address of these variables. Make sure to pay special attention to function signatures because you can end up with very strange results. Also, turn all warnings on for your compiler.

    scanf("%d %d", &hour, &min); 
    
    0 讨论(0)
  • 2020-11-28 17:22

    You could initialize your variables to their own addresses and "fix" this:

    int hour, min;
    hour = (int)&hour;
    min = (int)&min;
    

    (I am being a smart-ass, btw.)

    0 讨论(0)
  • 2020-11-28 17:23
    scanf("%d %d", &hour, &min);
    
    0 讨论(0)
提交回复
热议问题