Code:
#include <stdio.h>
#include <string.h>
int main ()
{
FILE *FF,*FP;
int temp=0;//temp is mainly used for a row to determine whether to delete, 0 means not delete, 1 means delete
Char a[1000];//place a row of fgets
Char b[1000];//to save user input
Char c[5]= "*\n";//This sets the specific character to "*"
printf (Please enter the start line to delete: \ n ");
scanf ("%s", b);//Enter the content to be deleted
Strcat (b, "\ n");//Because the Fgets function automatically adds a line break after the character being read, to compare A and B with strcmp, where b plus "\ n"
Ff=fopen ("Index.txt", "R")//Read Open the original file Index.txt
Fp=fopen ("Result.txt", "w");/write open temporary file Result.txt
if (Ff==null | | fp==null) {
printf ("Open file failed \ n");
Exit (0);/quit
}
while (Fgets (A,1000,FF))//Line to execute the contents of index.tzt
{
if (strcmp (a,b)!=0 && temp ==0)//if not equal to the input and temp is not equal to 0, do not delete
{
printf ("%s", a);//The content that is not deleted is exported to the console (consistent with the content of the result file)
Fputs (A,FP);//write content not deleted to Result.txt
}
else//find the line that matches the input
{
temp = 1;
if (strcmp (a,c) ==0)//encounters the next *, it is no longer deleted from the line
temp = 0;
}
}
Fclose (FF);//Close index file
Fclose (FP)//Close result file
return 0;
Execute Program:
Enter List1 to indicate the start of the line from the List1, until "*", the contents of the middle are all deleted
index.txt File
result.txt File