急求:有关c语言对文件中指定数据删除的有关问题,哪位高手能帮小弟我解答一下啊
急求:有关c语言对文件中指定数据删除的问题,谁能帮我解答一下啊?
要求对文本文件里面某段指定的内容进行删除,而且里面的内容很多,文件很大,有50多M,每段内容的形式都是一样的,如:1,tcp,ftp,SF,856,2586,0,0,0,18,0,1,0,0,0,0,0,0,0,0,0,1,1,1,0.00,0.00,0.00,0.00,1.00,0.00,0.00,221,44,0.20,0.03,0.00,0.00,0.00,0.00,0.00,0.00,normal
要求对其中一段内容进行删除,比如上面这行的内容。
我现在想到的解决方法是,把除了这段的其他内容复制到新的文件内,再复制回来,可是因为文件很大,应该会花很多的时间。另外一种想法是,把后面的字符一个一个前移覆盖,最后将整行数据覆盖,可是不知道怎么处理。另外一种想法是,把最后一行的数据覆盖这段数据,但是不知道有没有整行覆盖的命令,而且覆盖完了也不知道怎样删除。
我之前是用结构体存放这些数据的,类似这样,
struct genes{
int duration;
char p_type[5]; // protocol_type
char service[15];
char flag[4];
unsigned long src_bytes;
unsigned long dst_bytes;
int land;
int wrong_f; // wrong_fragment
int urgent;
int hot;
int num_fl; // num_failed_logins
int logged_in;
int num_com; // num_compromised
int root_shell;
int su_attemp; // su_attempted
int num_root;
int num_fc; // num_file_creations
int num_shells;
int num_af; // num_access_files
要求对文本文件里面某段指定的内容进行删除,而且里面的内容很多,文件很大,有50多M,每段内容的形式都是一样的,如:1,tcp,ftp,SF,856,2586,0,0,0,18,0,1,0,0,0,0,0,0,0,0,0,1,1,1,0.00,0.00,0.00,0.00,1.00,0.00,0.00,221,44,0.20,0.03,0.00,0.00,0.00,0.00,0.00,0.00,normal
要求对其中一段内容进行删除,比如上面这行的内容。
我现在想到的解决方法是,把除了这段的其他内容复制到新的文件内,再复制回来,可是因为文件很大,应该会花很多的时间。另外一种想法是,把后面的字符一个一个前移覆盖,最后将整行数据覆盖,可是不知道怎么处理。另外一种想法是,把最后一行的数据覆盖这段数据,但是不知道有没有整行覆盖的命令,而且覆盖完了也不知道怎样删除。
我之前是用结构体存放这些数据的,类似这样,
struct genes{
int duration;
char p_type[5]; // protocol_type
char service[15];
char flag[4];
unsigned long src_bytes;
unsigned long dst_bytes;
int land;
int wrong_f; // wrong_fragment
int urgent;
int hot;
int num_fl; // num_failed_logins
int logged_in;
int num_com; // num_compromised
int root_shell;
int su_attemp; // su_attempted
int num_root;
int num_fc; // num_file_creations
int num_shells;
int num_af; // num_access_files