#include <stdio.h>
#include <string.h>
int main(void)
{
char line[4096];
while (fgets(line, sizeof(line), stdin) != 0)
{
if (strncmp(line, "package ", sizeof("package ")-1) == 0)
{
while (fgets(line, sizeof(line), stdin) != 0)
{
if (strncmp(line, "procedure\n", sizeof("procedure\n")-1) == 0)
break;
fputs(line, stdout);
}
break;
}
}
return 0;
}
The code reads from standard input and writes to standard output. If you have data in file1
and want the results in file2
, use:
./program <file1 >file2
This is one of the beauties of standard input/standard output filters and shell I/O redirection.
Tested. Assuming no trailing blanks after the procedure
, the code now looks for "procedure\n"
. If you have to allow for possible trailing blanks or no trailing blanks, the comparison for procedure
is fiddlier.