简体   繁体   中英

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? 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?

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. 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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