include stdio include string include stdlib include locale int main in

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#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;
}