Current location - Plastic Surgery and Aesthetics Network - Jewelry brand - The latest jewelry
The latest jewelry
# include & ltstdio.h & gt

# include & ltstdlib.h & gt

int main(void)

{

char ch,filename[ 128],str[2 1],line[20 1];

int i = 0,j,k,m,lineNum = 0,isfirst = 0,firstLine = - 1,last line =- 1;

FILE * fp

Printf ("Enter file name and string:");

Scanf("%s%s ",file name, string);

Printf("-file content:-\ n ");

Fp = fopen (file name, "r");

if (fp == NULL)

{

Printf ("Cannot open file! \ n ");

Exit (1);

}

And (! feof(fp))

{

ch = fgetc(FP);

line[I]= ch;

i++;

If (ch == '\n')// If a line break is encountered,

{

linenum++; //Cumulative line

putchar(ch); //Output newline character

line[I]= ' \ 0 '; //Set the string end of the line.

I = 0; //I clear

}

Else if (ch == EOF)// If the end of the file is reached,

{

linenum++; //Cumulative line

line[I]= ' \ 0 '; //Set the string end of the line.

}

Else// The rest of the characters are directly output to the screen.

{

putchar(ch);

}

//Complete the output;

If (ch == '\n' || ch == EOF)// End of line or file encountered.

{

for (j = 0,k = 0; Ok [j]! = '\0'; j++)

{

//Check whether the string of line line contains the input string str (case-insensitive).

if((line[j]= = str[k])| |(line[j]= =(str[k]-32))| |(line[j]= =(str[k]+32)))

{

for(m = j; ((line[m]= = str[k])| |(line[m]= =(str[k]-32))| |(line[m]= =(str[k]+32)))

& amp& ampstr[k]! = '\0'; k++,m++)

{

;

}

if (str[k] == '\0 ')

{

if (isfirst == 0)

{

FirstLine = lineNum// Calculates the first equal occurrence of the line.

is first = 1;

}

LastLine = lineNum// Calculates the line where the last equation is located.

}

else if (line[m]! = str[k])

{

k = 0;

}

}

}

}

}

putchar(' \ n ');

Printf("-file summary:-\ n ");

Printf("%d line, first line: %d, last line: %d\n ",lineNum, first line, last line);

Returns 0;

}