源码
test.cpp
#include<string>
#include<iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main()
{
FILE *fd;
long dev;
long offset;
long length;
char ch;
double ts = 0.000000;
if ((fd = fopen("bbb.txt", "r"))<0)
{
printf("open the file is error!\n");
exit(0);
}
fseek(fd, 0, SEEK_SET);
while (!feof(fd))
{
fscanf(fd, "%ld,%ld,%ld,%c,%lf\n", &dev, &offset, &length, &ch, &ts);
printf("%ld,%ld,%ld,%c,%lf\n", dev, offset, length, ch, ts);
}
fclose(fd);
return 0;
}
测试文件:bbb.txt
2,50,41,w,20.585828
4,52,51,r,52.012547
编译
sudo g++ test.cpp
效果