fopen读取不了文件
程序代码:
#include<iostream> #include<stdio.h> #include<string.h> //void main_1(int *n_file_, FILE *open, FILE *write_8, FILE *write_9, FILE *write_10, FILE *write_11, FILE *write_12, FILE *write_13, FILE *write_14, FILE *write_15, FILE *write_16); void main_1(int * n_file_, FILE * open, FILE ** f_write_); void file_write(unsigned char *, FILE *); int length(unsigned char *a);//可以设定多个条件 int main() { FILE *f_open = NULL;//打开目标文件,可以改成把文件拖进来的相对路径 int n_file_[9] = { 0 }; if (fopen("test.txt","r+")==NULL) puts("打开文件成功\n\n"); else { puts("打开文件失败\n\n"); return 0; } FILE *f_write_[9] = { NULL };//生成的文件 f_write_[0] = fopen("length_1_8", "wb+"); f_write_[1] = fopen("length_9", "wb+"); f_write_[2] = fopen("length_10", "wb+"); f_write_[3] = fopen("length_11", "wb+"); f_write_[4] = fopen("length_12", "wb+"); f_write_[5] = fopen("length_13", "wb+"); f_write_[6] = fopen("length_14", "wb+"); f_write_[7] = fopen("length_15", "wb+"); f_write_[8] = fopen("length_over15", "wb+"); //main_1读取数据,分别写入相对于的文件 main_1(n_file_, f_open, f_write_); // cul(f_write_[0],n_file_[0]);//目标文件;文件存储长度 fclose(f_open); for (int i = 0; i < 9; i++) fclose(f_write_[i]); return 0; } //void main_1(int *n_file_, FILE *open, FILE *write_8, FILE *write_9, FILE *write_10, FILE *write_11, FILE *write_12, FILE *write_13, FILE *write_14, FILE *write_15, FILE *write_16) void main_1(int * n_file_, FILE * open, FILE ** file) { // FILE *file[9] = { write_8, write_9, write_10, write_11, write_12, write_13, write_14, write_15, write_16 }; unsigned char temp[20]; int i; while (!feof(open))//判断是否到文件尾部 { fscanf(open, "%s ", temp);//从文件读取一个字符串 i = length(temp);//根据字符串长度确定输入哪一个文件,若返回值为0,则跳过这个字符串 if (i == 0) continue; else if (i < 9)//写入对应的文件 { file_write(temp, file[0]); n_file_[0]++; } else if (i>15) { file_write(temp, file[8]); n_file_[8]++; } else { file_write(temp, file[i - 8]); n_file_[i - 8]++; } } } int length(unsigned char *a)//可以设定多个条件 { static int n = 0; if (n++ % 5 != 2) return 0; return strlen((char *)a); } void file_write(unsigned char * a, FILE * file) { fprintf(file, "%s", a); fprintf(file, " "); }
昨天程序调试的时候还能正常运行,今天早上把一个200M左右的文件进行操作,没成功;之后就出现了无法读取文件的情况:代码调试以后,f_open总是无法读取到内存然后就结束了。