Instantly share code, notes, and snippets.

@thinkphp /copy.c
Last active Nov 1, 2018

Embed
What would you like to do?
mv filename1 filename2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
int main(int argc, int **argv) {
char ch;
FILE *source, *target;
char source_file[40], target_file[40];
char *p;
if(argv[1] == NULL || argv[2] == NULL) {
printf("Argv[1] and Argv[2] are missing!");
exit(EXIT_FAILURE);
}
strcpy(source_file, argv[1]);
source = fopen(argv[1], "r");
if(source == NULL) {
printf("Press ny key to exit");
exit(EXIT_FAILURE);
}
strcpy(target_file, argv[2]);
target = fopen(target_file, "w");
while((ch = fgetc(source)) != EOF) fputc(ch, target);
printf("\nFile compied successfully!\n");
fclose(source);
fclose(target);
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment