简体   繁体   English

fscanf读取小时格式

[英]fscanf to read hour format

Is there a way to read a HH:MM format from a file using fscanf() , and treat it like an int? 有没有办法使用fscanf()从文件中读取HH:MM格式,并将其视为int类型? The file has this format : 该文件具有以下格式:

3 14:50 20.10

Is it possible to do something like fscanf(fp, "%d ... %f, &a, &b, &c); and b will have 1450? 是否可以做类似fscanf(fp, "%d ... %f, &a, &b, &c);类的事情fscanf(fp, "%d ... %f, &a, &b, &c);并且b将有1450?

I'm afraid you can't do this in a line. 恐怕你不能一齐做到这一点。 However, you can: 但是,您可以:

fscanf(fp, "%d %d:%d %f", &a, &b1, &b2, &c);
b = b1 * 100 + ((b1 > 0) * 2 - 1) * b2; // in case b1, b2 are the different sign. 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM