我正在打开一个文件,使用 读取第一行fgets
,使用regexp
来测试文件的格式,如果文件是所需的格式,我使用fscanf
读取整个文件。
fid = fopen('E:\Tick Data\Data Output\Differentformatfiles\AUU01.csv','rt');
% reads first line of file but seems to be deleting the line:
str = fgets(fid);
% test for pattern mm/dd/yyyy
if(regexp(str, '\d\d/\d\d/\d\d\d\d'))
c = fscanf(fid, '%d/%d/%d,%d:%d:%d,%f,%d,%*c');
不幸的是,如果我的文件内容如下所示:
20010701,08:29:30.000,95.00,29,E
20010702,08:29:30.000,95.00,68,E
20010703,08:29:30.000,95.00,5,E
20010704,08:29:30.000,95.00,40,E
20010705,08:29:30.000,95.00,72,E
str
将等于20010701,08:29:30.000,95.00,29,E
,但c
仅等于最后 4 行:
20010702,08:29:30.000,95.00,68,E
20010703,08:29:30.000,95.00,5,E
20010704,08:29:30.000,95.00,40,E
20010705,08:29:30.000,95.00,72,E
有没有办法防止fgets
删除第一行?还是我应该使用的其他功能?