×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: C
Posted by: Damian Pytkowski
Added: May 21, 2016 1:39 PM
Modified: May 21, 2016 2:07 PM
Views: 2160
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <windows.h>
  5. #include <string.h>
  6. #define ROZ 12
  7. int countKey(char *key,char *source);
  8. void copy(char *source, char *target);
  9. void main(int argc,char *argv[])
  10. {
  11.    int count;
  12.    copy(argv[1],argv[2]);
  13.  
  14. }
  15. int countKey(char *key,char *source)
  16. {
  17.     FILE *fr;
  18.     int i=0,counter=0;
  19.     char c;
  20.     if((fr=fopen(source,"r"))==NULL) printf("Unable to read to file.");
  21.  
  22.     while(!feof(fr)){
  23.         c=fgetc(fr);
  24.         if(c==key[i++]){
  25.             if(i==strlen(key))counter++;
  26.         }
  27.         else i=0;
  28.     }
  29.     return counter;
  30. }
  31.  
  32. void copy(char *source, char *target)
  33. {
  34.     FILE *fr,*fw;
  35.     char c;
  36.     if((fr=fopen(source,"r"))==NULL) printf("Unable to read to file.");
  37.     if((fw=fopen(target,"w"))==NULL) printf("Unable to write to file.");
  38.     c=getc(fr);
  39.     while(!feof(fr))
  40.     {
  41.         putc(c,fw);
  42.         c=getc(fr);
  43.     }
  44. }
  45.