Skip to content

Commit

Permalink
Step 1: MyCopy finished
Browse files Browse the repository at this point in the history
  • Loading branch information
cnphil committed Mar 30, 2013
1 parent 0f9d2fa commit fcaf107
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Binary file added MyCopy
Binary file not shown.
35 changes: 35 additions & 0 deletions MyCopy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "cse356header.h"

main(int argc, char *argv[])
{
FILE *src;

src = fopen(argv[1], "r");

if(src == NULL) {
printf("Error: Could NOT open file \"%s\".\n", argv[1]);
exit(-1);
}

FILE *dest;

dest = fopen(argv[2], "w+");

if(dest == NULL) {
printf("Error: Could NOT open file \"%s\".\n", argv[2]);
fclose(src);
exit(-1);
}

// copying begins
char *buffer[256];
while (true) {
int read_chars = fread(buffer, sizeof(char), 255, src);
if(read_chars <= 0) break;
fwrite(buffer, sizeof(char), read_chars, dest);
}
fclose(src);
fclose(dest);

exit(0);
}
15 changes: 15 additions & 0 deletions cse356header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef CSE356HEADER_H_
#define CSE356HEADER_H_
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <wait.h>
#include <signal.h>
#include <sstream>
#include <pthread.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include <sys/time.h>
#endif /*CSE356HEADER_H_*/
7 changes: 7 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
all: MyCopy
clear:
rm *.o
MyCopy: MyCopy.o
g++ MyCopy.o -o MyCopy
MyCopy.o:
g++ -c MyCopy.c

0 comments on commit fcaf107

Please sign in to comment.