#include #include #include int main ( int argc, char **argv ) { FILE *fpin, *fpout; char line[1024]; char name[512]; int i; if (argc != 2) { printf ("Usage: %s \n", argv[0]); exit (-1); } fpin = fopen (argv[1], "r"); if (!fpin) { perror ("fopen"); exit (-1); } fpout = NULL; i = 0; while (!feof (fpin)) { fgets (line, 1023, fpin); if (!strncmp (line, "Index:", 6)) { if (fpout) fclose (fpout); i++; sprintf (name, "hunk.%d", i); fpout = fopen (name, "w"); if (!fpout) { perror ("fopen"); exit (-1); } } fputs (line, fpout); } fclose (fpin); if (fpout) fclose (fpout); return (0); }