Skip to content

Instantly share code, notes, and snippets.

@kano4
Created February 25, 2013 12:25
Show Gist options
  • Save kano4/5029509 to your computer and use it in GitHub Desktop.
Save kano4/5029509 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(int argc, char const* argv[])
{
FILE *infile;
FILE *outfile;
char buf[256];
int i;
if ((infile = fopen(argv[1], "r")) == NULL) {
fprintf(stderr, "1: File open error!\n");
}
if ((outfile = fopen("./sample.txt", "w")) == NULL) {
fprintf(stderr, "2: File open error!\n");
}
while (fgets(buf, sizeof(buf), infile) != NULL) {
fwrite("0x", 1, 2, outfile);
for (i = 0; i < 8; i++) {
fwrite(buf + 6 + 3 * i, 1, 2, outfile);
fwrite(", 0x", 1, 4, outfile);
}
for (i = 0; i < 7; i++) {
fwrite(buf + 31 + 3 * i, 1, 2, outfile);
fwrite(", 0x", 1, 4, outfile);
}
fwrite(buf + 31 + 3 * 7, 1, 2, outfile);
fwrite(",", 1, 1, outfile);
fwrite("\n", 1, 1, outfile);
}
fclose(outfile);
fclose(infile);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment