我正在编写一个打开txt文件的ac程序,想要读取txt文件的最后一行.我不是那么精通C所以请记住,我可能不知道C中的所有概念.我被困在我使用fscanf读取我的txt文件的所有行的部分,但我想采取最后一行txt文件并获取如下所述的值.
这是我不完整的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *sync;
void check()
{
int success; //to hold the results if the timestamps match
sync = fopen("database.txt","r");
char file[] = "database.txt";
while (fscanf(sync, "%d.%06d", &file) != EOF)
{
}
fclose(sync);
}
Run Code Online (Sandbox Code Playgroud)
示例txt文件:
/////// / //// ///// ///// //////////////// Time: 1385144574.787665 //////// /
/////// / //// ///// ///// //////////////// Time: 1385144574.787727 //////// /
/////// / //// ///// ///// //////////////// Time: 1385144574.787738 //////// /
/////// / //// ///// ///// //////////////// Time: 1385144574.787746 //////// …Run Code Online (Sandbox Code Playgroud)