当前位置:网站首页>Console program for viewing BMP files

Console program for viewing BMP files

2022-06-11 07:12:00 lihongtao8209

1.DEV 5.0

Program usage DEV 5.0 Development . But because the author's operating system is Chinese , So use printf Print more than ASCII code 128 I will appear Chinese garbled code . This is because two are greater than 128 Of ASCII Of WINDOWS In the Chinese system, it is changed to by default GB2312 Chinese characters of . The solution is , Open console , Turn the current environment into English .

-----------------------------------------------------------------------------
Console command |Windows Console code page code | meaning    |
-----------------------------------------------------------------------------
chcp              |437                                          | American English |
------------------------------------------------------------------------------
chcp              |936                                          | chinese GBK |
-------------------------------------------------------------------------------

chcp The order is : chcp code page .

2.WIN TC

Later, the operating system was reinstalled , stay 64M Move U Found it on the disk WINTC This compiler . compile 、 Run it ,OK. No need to change the code page .

3.DEV 5.0 Code

/*
---------------------------------------------
 Console command  |Windows Console code page code  | meaning     |
----------------------------------------------
chcp       |437                     | American English |
----------------------------------------------
chcp       |936                     | chinese GBK |
----------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#define INFO_LEN 17
int main(int argc, char** argv) {
	int  ch=0;
	int  index=0;
	int  row=0;
	char chs[INFO_LEN];
	FILE *fp=NULL; 
	memset((void*)chs,0,INFO_LEN);
	fp=fopen("1.bmp","rb");
	if(fp==NULL)
	{
		printf("not exist file.\n");
		return -1;
	}
	if(index==0)
	{
		printf("%3s"," ");
		for(int i=0;i<16;i++)
		{
			printf("%02X ",i);
		}
		printf("\n");
	}
	do{
		ch=fgetc(fp);
		if(index%16==0 )
		{
			if(index!=0)
			{
				//printf(" %s\n",chs);
				printf(" ");
				for(int i=0;i<16;i++)
					putchar(chs[i]);
				printf("\n");
			}
			printf("%02X ",row++);
			memset((void*)chs,0,INFO_LEN);
		}
		printf("%02x ",ch);
		//
		if(ch>=32 &&ch <=254)
			chs[index%16]=ch;
		else if(ch>=1 && ch <=8)
			chs[index%16]=ch;
		else if(ch==9 || ch==10 || ch==13||ch==0)
			chs[index%16]=152;
		else if(ch>=14 && ch<=31)
			chs[index%16]=ch;
		else
			chs[index%16]='.';
		//
		index++;
	}while(!feof(fp));
	fclose(fp);
	return 0;
}

4.WIN TC Code

#include <stdio.h>
#include <string.h>
#define INFO_LEN 17
int main(int argc, char** argv) {
    int  i=0;
    int  ch=0;
    int  index=0;
    int  row=0;
    char chs[INFO_LEN];
    FILE *fp=NULL; 
    memset((void*)chs,0,INFO_LEN);
    fp=fopen("1.bmp","rb");
    if(fp==NULL)
    {
        printf("not exist file.\n");
        getchar();
        return -1;
    }
    if(index==0)
    {
        printf("%3s"," ");
        for(i=0;i<16;i++)
        {
            printf("%02X ",i);
        }
        printf("\n");
    }
    do{
        ch=fgetc(fp);
        if(index%16==0 )
        {
            if(index!=0)
            {
                /*printf(" %s\n",chs);*/
                printf(" ");
                for( i=0;i<16;i++)
                    putchar(chs[i]);
                printf("\n");
            }
            printf("%02X ",row++);
            memset((void*)chs,0,INFO_LEN);
        }
        printf("%02x ",ch);
        /*********************************/
        if(ch>=32 &&ch <=254)
            chs[index%16]=ch;
        else if(ch>=1 && ch <=8)
            chs[index%16]=ch;
        else if(ch==9 || ch==10 || ch==13||ch==0)
            chs[index%16]=152;
        else if(ch>=14 && ch<=31)
            chs[index%16]=ch;
        else
            chs[index%16]='.';
        /*********************************/
        index++;
    }while(!feof(fp));
    fclose(fp);
    getch();
    return 0;
}

 

原网站

版权声明
本文为[lihongtao8209]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020522382525.html