53 lines
1.5 KiB
C
53 lines
1.5 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
|
int main(int argc, char **argv){
|
||
|
if(argc == 1){
|
||
|
printf("\033[1;31m"); //red
|
||
|
printf("error: ");
|
||
|
printf("\033[0;37m"); //white
|
||
|
printf("no input and output file!\n");
|
||
|
return -1;
|
||
|
}
|
||
|
if(argc == 2){
|
||
|
printf("\033[1;31m"); //red
|
||
|
printf("error: ");
|
||
|
printf("\033[0;37m"); //white
|
||
|
printf("no output file!\n");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
if(access(argv[1], F_OK ) == 0) {
|
||
|
//none
|
||
|
} else {
|
||
|
printf("\033[1;31m"); //red
|
||
|
printf("error: ");
|
||
|
printf("\033[0;37m"); //white
|
||
|
printf("cannot open file!\n");
|
||
|
return -1;
|
||
|
}
|
||
|
printf("\033[0;37m"); //white text
|
||
|
|
||
|
FILE * file; //file pointer
|
||
|
file = fopen(argv[1], "rb"); //open file
|
||
|
fseek(file, 0L, SEEK_END); //seek file size
|
||
|
size_t filesize = ftell(file); //get file size
|
||
|
|
||
|
unsigned int filedata[filesize]; //make file data table
|
||
|
fread(filedata, filesize, 1, file); //set file data in filedata table
|
||
|
|
||
|
fclose(file); //close input file
|
||
|
|
||
|
//put here data manipulation
|
||
|
|
||
|
file = fopen(argv[2], "wb"); //open output file
|
||
|
|
||
|
//write final data in output file
|
||
|
fwrite(filedata , sizeof(char) , filesize , file);
|
||
|
|
||
|
fclose(file); //close output file
|
||
|
|
||
|
return 1;
|
||
|
}
|