如何将数据读入一个time_t的使用可变scanf()的? [英] How to read data into a time_t variable using scanf()?
本文介绍了如何将数据读入一个time_t的使用可变scanf()的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这code给我的警告:
This code gives me warnings:
$ cat test.c
#include<stdio.h>
#include<time.h>
int main() {
time_t t;
scanf("%lld", &t);
printf("%lld\n", t);
return 0;
}
$ gcc test.c -o test
test.c: In function ‘main’:
test.c:7: warning: format ‘%lld’ expects type ‘long long int *’, but argument 2 has type ‘time_t *’
test.c:8: warning: format ‘%lld’ expects type ‘long long int’, but argument 2 has type ‘time_t’
$
除了警告,在code正常工作。
Apart from the warnings, the code works as expected.
我应该怎么做才能不下去了编译警告(没有编译器编译招数讨好)?
What should I do to not get the warnings on compilation (no compiler pragma tricks please)?
推荐答案
time_t的
的确切类型取决于您的平台和操作系统上。它仍然是相当频繁的32位(或 INT
或长
),而不是64,有的甚至使用花车。做正确的事情是读入一个已知大小的整数( INT
或长长
),然后分配的值以一个 time_t的
作为第二步骤
The exact type of time_t
depends on your platform and OS. It's still quite often 32 bit (either int
or long
), not 64, and some even use floats. The correct thing to do is to read into a known-size integer (either int
or long long
) and then assign the value to a time_t
as a second step.
这篇关于如何将数据读入一个time_t的使用可变scanf()的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文