time.h:打印时间在屏幕上还有另一个'%'

时间:2016-01-15 14:37:14

标签: c printf time.h

这是我试图理解的一个程序。

消息来源

typedef float Time;

Time getCurrentTime() {
    time_t rawtime;
    struct tm * timeinfo;
    Time currentTime;
    time ( &rawtime );                            //get system time
    timeinfo = localtime ( &rawtime );//convert to local time 
    // tm_hour, tm_min
    currentTime = (float)timeinfo->tm_hour + timeinfo->tm_min * 0.01;
    printf("InnerTime:%7.2f\n", currentTime);
    return currentTime;
}

int main(void) {
    Time tm = getCurrentTime();
    printf("OuterTime:%7.2f", tm);
    return 0;
}

Run Results

为什么在%的末尾还有另外一个OuterTime? 但%结尾没有InnerTime

2 个答案:

答案 0 :(得分:2)

这很可能是你的shell提示。添加\ n以确定。

答案 1 :(得分:1)

在外部时间打印中,您错过了在格式字符串中包含.ui-widget-overlay { position: absolute; top: 0; left: 0; width:100%; height:100%; background: #aaaaaa; opacity: 0.3; } .ui-dialog { background-color: #FFFFFF; overflow: hidden; z-index:1; } ,因此在程序打印完最后一个输出并退出后,提示会在打印后立即返回输出

尝试

newline

强制提示出现在下一行。