Home
Software Programming Learning
EDA & IP & IC
Goodies
News
Contact Us
Article
Contents Of Article
Previous Article
SNO:
Writer:
Next Article
Title:
/* * XOR FILE ENCODER/DECDOER PROGRAM * By Joseph Ku, AdvTechLink.com * On 2014/09/20 * Copyright @ 2014 AdvTechLink.com */ #include <stdio.h> int main(int argc, char **argv){ if (argc == 1 || argc != 4){ printf("Usage: xorfilecodec dataFileName codeFileName resultFileName"); return 0; } FILE *fpr1, *fpr2, *fpw; fpr1 = fopen(argv[1],"rb"); fpr2 = fopen(argv[2],"rb"); fpw = fopen(argv[3],"wb"); if (fpr1){ printf("SUCCESS of accessing the Data File!\n"); } else { printf("FAILURE of accessing the Data File!\n"); return 0; } if (fpr2){ printf("SUCCESS of accessing the Codebook!\n"); } else { printf("FAILURE of accessing the Codebook!\n"); fclose(fpr1); return 0; } if (fpw){ printf("SUCCESS of opening the Result File!\n"); } else { printf("FAILURE of opening the Result File!\n"); fclose(fpr1); fclose(fpr2); return 0; } char cf[1], cc[1], cw[1]; while((fread(cf,1,1,fpr1))==1){ if (fread(cc,1,1,fpr2)==0) { fseek(fpr2,0,SEEK_SET); fread(cc,1,1,fpr2); } cw[0]= cf[0] ^ cc[0]; fwrite(cw,1,1,fpw); } printf("Conversion is completed!\n"); fclose(fpw); fclose(fpr1); fclose(fpr2); return 0; }
Previous Article
Next Article