Guest User

ря

a guest
Jun 13th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main (int argc, char **argv)
  6. {
  7.     FILE *file_in, *file_out;
  8.     char buff[300];
  9.     int len;
  10.  
  11.     if (argc > 2)
  12.     {
  13.         if ((file_in = fopen(argv[1], "r")) != NULL)
  14.             if ((file_out = fopen(argv[2], "w")) != NULL)
  15.             {
  16.                 while (!feof(file_in))
  17.                 {
  18.                     if (fgets(buff, 228, file_in))
  19.                     {
  20.                         len = strlen(buff);
  21.                         if (buff[len - 2] == argv[3][0])
  22.                         {
  23.                             printf("%s", buff);
  24.                             fprintf(file_out, "%s", buff);
  25.                         }
  26.                     }
  27.                 }
  28.                 fclose(file_in);
  29.                 fclose(file_out);
  30.             }
  31.             else
  32.                 puts("file could not be created!");
  33.         else
  34.             puts("file could not be opened!");
  35.     }
  36.     else
  37.         puts("too few arguments!\nUsage:\nfindstr.exe [source file] [destination file] [last symbol in string]");
  38.  
  39.     system("pause");
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment