#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
	int srcfd;
	FILE *output;
	char buf[256];
	
	if(!argv[1] || !argv[2]) {
		printf("Usage: %s [src file] [dst file]\n",argv[0]);
		exit(1);
	}
	if(!(srcfd=open(argv[1],O_RDONLY))) {
		printf("Couldn't open %s!\n", argv[1]);
		exit(1);
	}
	if((output=fopen(argv[2],"w")) == NULL) {
		printf("Couldn't write file\n");
		exit(1);
	}
	while(read(srcfd,buf,2)) {
		fprintf(output,"%c%c",buf[1],buf[0]);
	}
	fclose(output);
	close(srcfd);
}
