バグがあるけど気にするな。
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <jctype.h>
#include <mbstring.h>
#include <jstring.h>
#define SJIS_MIN 0x8140L
#define SJIS_MAX 0xeaa4L
#define PER_LINE 16 //1行の文字数
#define TRUE ((unsigned char)1)
#define FALSE ((unsigned char)0)
int main()
{
typedef unsigned char BOOL;
FILE *fp;
char buf[3];
unsigned long i;
int j;
BOOL isPrintable;
fp = fopen("sjis.txt","w");
if(!fp){
printf("fileopen error");
return EXIT_FAILURE;
}
//HEADER BEGIN
fprintf(fp,"SJIS");
if(PER_LINE<=16){
for(i=0;i<PER_LINE;i++)
fprintf(fp," +%X",i);
}
else{
for(i=0;i<16;i++)
fprintf(fp," +%X",i);
for(i=16;i<PER_LINE;i++)
fprintf(fp,"+%X",i);
}
//HEADER END
for(i=SJIS_MIN; i < SJIS_MAX + 1L ; i++){
if((i % PER_LINE) == 0L){
isPrintable = FALSE;
for(j=i ; j<i+PER_LINE;j++){
if(jisprint(j)){
isPrintable = TRUE;
break;
}
}
if(isPrintable == FALSE){
i += PER_LINE;
}
else
fprintf(fp,"\n%X ",i);
}
if(isPrintable == TRUE){
*((unsigned short*)(buf)) = (unsigned short)i;
buf[2] = 0;
if(jisprint(i))
fprintf(fp,"%2s " , buf);
else
fprintf(fp," ");
}
}
fclose(fp);
return EXIT_SUCCESS;
}