G
George
I continue to try to implement a black word/white word encoding similar to
the treatment given in chp. 18 of _unleashed_.
#include <stdio.h>
#include <stdlib.h>
#define PATH "george.txt"
#define NUMBER 100
#define MAXFMTLEN 2000
int main(void)
{
FILE *fp;
char pattern[MAXFMTLEN];
char lbin[NUMBER];
char line[MAXFMTLEN];
if ((fp = fopen(PATH, "r")) == NULL ) {
fprintf(stderr, "can't open file\n");
exit(1);
}
sprintf(pattern, "%%*s %%%ds", NUMBER-1);
while(fgets(line, MAXFMTLEN, fp) == line){
sscanf(line, pattern , lbin);
printf("%s\n", lbin);
}
fclose(fp);
return 0;
}
// gcc -o x.exe chad6.c
output is:
C:\MinGW\source>gcc -o x.exe chad6.c
C:\MinGW\source>x
0001000000000000001
0001000000000000001
10000011001000000000000001
10000011001000000000000001
10000011001000000000000001
10000011001000000000000001
10000011001000000000000001
10000011001000000000000001
10000011001000000000000001
10000011001000000000000001
100000001111100
100000001111100
100000001111100
1000001110110111100000000000001
1000001110110111100000000000001
1000001110110111100000000000001
1000001110110111100000000000001
1000001110110111100000000000001
1000001110110111100000000000001
0001000000000000001
The next step is to herd these into bytes. I tried to follow what Jack
Klein does, but his encode.c is too complex for me to follow, and it's 20
K. I'm able to do it in fortran and know that the file I want looks like:
C:\MinGW\source>od -tx1 -Ax -v bin3.dat
C:\MinGW\source>dump bin3.dat
000000 0d 0a 10 00 22 00 06 0c 80 01 83 20 00 60 c8 00
000010 18 32 00 06 0c 80 01 83 20 00 60 c8 00 18 32 00
000020 06 03 e4 20 c8 0f 90 76 f0 00 60 ed e0 00 c1 db
000030 c0 01 83 b7 80 03 20 6f 00 06 0e de 00 08 80 01
000040
, without the initial crlf. I added that because encode.c to try to be
kosher with the usage (it would make my code garbage). Maybe, hints of of
why I don't succeed follow:
C:\MinGW\source>gcc encode1.c -o prog.exe
C:\MinGW\source>prog
usage: encode binary-input-file, t4-output-file
C:\MinGW\source>prog bin3.dat out.t4
encoded 0 rows from bin3.dat to out.t4
It's kind of a rambling post; let me restate my intent. I'd like to herd
the ones and zeroes in char lbin[NUMBER] into bytes. I have 8 bit bytes,
but there isn't any reason not to write it portably. The final byte is to
be padded with zeroes to the left. The output I believe to be correct is
the last 62 values in the hex dump.
Thanks for your comment.
--
George
I will never relent in defending America - whatever it takes.
George W. Bush
Picture of the Day http://apod.nasa.gov/apod/
the treatment given in chp. 18 of _unleashed_.
#include <stdio.h>
#include <stdlib.h>
#define PATH "george.txt"
#define NUMBER 100
#define MAXFMTLEN 2000
int main(void)
{
FILE *fp;
char pattern[MAXFMTLEN];
char lbin[NUMBER];
char line[MAXFMTLEN];
if ((fp = fopen(PATH, "r")) == NULL ) {
fprintf(stderr, "can't open file\n");
exit(1);
}
sprintf(pattern, "%%*s %%%ds", NUMBER-1);
while(fgets(line, MAXFMTLEN, fp) == line){
sscanf(line, pattern , lbin);
printf("%s\n", lbin);
}
fclose(fp);
return 0;
}
// gcc -o x.exe chad6.c
output is:
C:\MinGW\source>gcc -o x.exe chad6.c
C:\MinGW\source>x
0001000000000000001
0001000000000000001
10000011001000000000000001
10000011001000000000000001
10000011001000000000000001
10000011001000000000000001
10000011001000000000000001
10000011001000000000000001
10000011001000000000000001
10000011001000000000000001
100000001111100
100000001111100
100000001111100
1000001110110111100000000000001
1000001110110111100000000000001
1000001110110111100000000000001
1000001110110111100000000000001
1000001110110111100000000000001
1000001110110111100000000000001
0001000000000000001
The next step is to herd these into bytes. I tried to follow what Jack
Klein does, but his encode.c is too complex for me to follow, and it's 20
K. I'm able to do it in fortran and know that the file I want looks like:
C:\MinGW\source>od -tx1 -Ax -v bin3.dat
C:\MinGW\source>dump bin3.dat
000000 0d 0a 10 00 22 00 06 0c 80 01 83 20 00 60 c8 00
000010 18 32 00 06 0c 80 01 83 20 00 60 c8 00 18 32 00
000020 06 03 e4 20 c8 0f 90 76 f0 00 60 ed e0 00 c1 db
000030 c0 01 83 b7 80 03 20 6f 00 06 0e de 00 08 80 01
000040
, without the initial crlf. I added that because encode.c to try to be
kosher with the usage (it would make my code garbage). Maybe, hints of of
why I don't succeed follow:
C:\MinGW\source>gcc encode1.c -o prog.exe
C:\MinGW\source>prog
usage: encode binary-input-file, t4-output-file
C:\MinGW\source>prog bin3.dat out.t4
encoded 0 rows from bin3.dat to out.t4
It's kind of a rambling post; let me restate my intent. I'd like to herd
the ones and zeroes in char lbin[NUMBER] into bytes. I have 8 bit bytes,
but there isn't any reason not to write it portably. The final byte is to
be padded with zeroes to the left. The output I believe to be correct is
the last 62 values in the hex dump.
Thanks for your comment.
--
George
I will never relent in defending America - whatever it takes.
George W. Bush
Picture of the Day http://apod.nasa.gov/apod/