我有下面的代码,当我在没有第int milli =
20 行(靠近底部)的情况下运行它时,它运行得很好,但是当我将函数的结果分配给变量 ( milli
) 时,它会引发分段错误。我看不出有什么区别会导致段错误。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
// convert a timeval and time to milliseconds of today
int seconds_of_day(struct timeval *sec, struct tm *tim){
long int milli_since_epoch = (sec->tv_sec * 1000)+(sec->tv_usec/100);
return 0; // this is return 0 only for debugging
}
int main(){
struct timeval *timeval_struct;
time_t rawtime;
struct tm *tm_struct;
gettimeofday(timeval_struct, NULL);
time(&rawtime);
tm_struct = gmtime(&rawtime);
int milli = seconds_of_day(timeval_struct, tm_struct);
return(0);
}