TEST1 – 20113 Q1

Posted: March 1, 2012 in Uncategorized
#include <cstdio>


void concat(int no, char** file) {
  FILE* fp1 = fopen(file[1], "w");
  FILE* fp2;      
  int i;
  char ch;

  for(i = 2; i < no ; i++){
    fp2 = fopen(*(file+i), "r");
    while((ch=fgetc(fp2))!=EOF){
      fputc(ch, fp1);
    }
    fclose(fp2);
  }
  fclose(fp1);
}

    
int main(int argc, char** argv) {
  if(argc < 3)
    printf("Usage: %s DestFile SrcFile1 [SrcFile2 SrcFile3 ...]<ENTER>\n", *argv);
  else
    concat(argc, argv);
  return 0;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s