我正在尝试读取多个文件。文件的格式类似于YYYY-mm-dd-HH-MM.txt
,例如2012-11-26-18-50.txt
我有以下代码
char text_buffer[1000];
char file_buffer[256];
int year, month, day, hour, minute;
year = 2012; month = 11; day = 26; hour = 18; minute = 0;
sprintf(file_buffer, "%d-%d-%d-%d-%d.txt", year, month,day,hour,minute);
FILE *ptr_file;
ptr_file=fopen(file_buffer, "r");
if(ptr_file != NULL)
printf("File opened %s for reading.\n", file_buffer);
else
printf("Couldn't open %s.\n", file_buffer);
line_number = 0;
while(fgets(buffer,sizeof(buffer), ptr_file) != NULL){
if(strcmp(buffer, "")==0)
return 0;
char *views = strok(buffer, ",");
...
}
我假设这就是所需的所有信息。如果仍然不清楚我的问题出在哪里,我会发布所有这些。当我运行程序时。我得到了
Filed opened...
和Couldn't open...
。然后是分段错误。
有人可以帮我解决这个问题吗?
谢谢。