#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <locale.h>
int main()
{
int size, i, j=1;
char *p, word[]="for";
size_t word_len = strlen(word);
FILE *text;
setlocale(LC_ALL,"");
if ((text=fopen("main1.c","rb"))==NULL)
{
perror("");
return EXIT_FAILURE;
}
else
{
fseek(text, 0L, SEEK_END);
size = ftell(text);
fseek(text, 0L, SEEK_SET);
char *buffer = (char *)malloc(size+1);
fread((void *)buffer, 1, size, text);
//-----------------------------------
while (p=strstr(buffer, word))
memmove(p, p+word_len, strlen(p+word_len)+1);
printf(" %s\n", buffer);
//-----------------------------------
for(i=0; i<size; i++)
{
switch(buffer[i])
{
case '\n': {j++; continue;}
default:
{
if (strncmp(&buffer[i], "printf", 6)==0 || strncmp(&buffer[i], "scanf", 5)==0)
printf("printf %i\n",j);
}
}
}
}
return 0;
}