Advertisement
Adytzu04

concatenare fisiere

May 22nd, 2012
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <io.h>
  5. #include <fcntl.h>
  6.  
  7. int main(int argc, char* argv[])
  8. {
  9.         int i, ch;
  10.         FILE *fi, *fo;
  11.         for(i=1;i<argc;i++)
  12.         {
  13.                 printf("\n\t%s\n",argv[i]);
  14.                 fi=fopen(argv[i],"r");
  15.                 if(!fi)
  16.                 {
  17.                         fprintf(stderr,"Eroare la deschiderea fisierului in!");
  18.                         exit(EXIT_FAILURE);
  19.                 }
  20.                 else
  21.                 {
  22.                         fo = fopen("final.txt","a");
  23.                         if(!fo)
  24.                         {
  25.                                 fprintf(stderr,"Eroare la deschiderea fisierului out!");
  26.                                 exit(EXIT_FAILURE);
  27.                         }
  28.                         else
  29.                         {
  30.                                 while(!feof(fi))
  31.                                 {
  32.                                         ch = (char)fgetc(fi);
  33.                                         if(!feof(fi))
  34.                                                 fputc((int)ch, fo);
  35.                                 }
  36.                         }
  37.                         fclose(fo);
  38.                 }
  39.                 fclose(fi);
  40.         }
  41.         return 0;
  42. }
  43. ////concateneaza .c ;  .txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement