2024/3/3

#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
    FILE* fp = fopen("R-C.bmp","r");

    fseek(fp,2,SEEK_SET);
    int bmp_size = 0;
    fread(&bmp_size,4,1,fp);
    printf("文件大小为 %d 字节\n",bmp_size);

    int w = 0,h = 0;
    fseek(fp,18,SEEK_SET);
    fread(&w,4,1,fp);
    fread(&h,4,1,fp);
    printf("图像尺寸为:%d * %d\n",w,h);

    fclose(fp);

    fp = fopen("R-C.bmp","r+");

    fseek(fp,54,SEEK_SET);
    // bmp 图片默认像素格式是 bgr的
    unsigned char pix1[3] = {0,255,255};
    for(int i=0;i<w;i++)
	{
        for(int j=0;j<h/3;j++)
		{
            fwrite(pix1,3,1,fp);
        }
    }
	unsigned char pix2[3] = {0,0,255};
	for(int i=0;i<w;i++)
	{
        for(int j=0;j<h/3;j++)
		{
            fwrite(pix2,3,1,fp);
		}
	}
	unsigned char pix3[3] = {0,0,0};
	for(int i=0;i<w;i++)
	{
        for(int j=0;j<h/3;j++)
		{
            fwrite(pix3,3,1,fp);
		}
	}

    fclose(fp);

    return 0;
}
#include<stdio.h>
  2 #include<string.h>
  3 #include<stdlib.h>
  4 #include <termios.h>
  5 #include <unistd.h>
  6 #include <sys/types.h>
  7 #include <assert.h>
  8 
  9 int getch()
 10 {
 11     int c=0;
 12     struct termios org_opts, new_opts;
 13     int res=0;
 14     res=tcgetattr(STDIN_FILENO, &org_opts);
 15     assert(res==0);
 16 
 17     new_opts = org_opts;
 18 
 19     new_opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL);
 20     tcsetattr(STDIN_FILENO, TCSANOW, &new_opts);
 21 
 22     c=getchar();
 23 
 24     res=tcsetattr(STDIN_FILENO, TCSANOW, &org_opts);
 25     assert(res==0);
 26     return c;
 27 }
 28 
 29 int main(int argc, char *argv[])
 30 {
 31      char c;
 32      char arr[8]={0};
 33      int i=0;
 34      for(i=0;arr[i-1]!='\n'&&i<8;i++)                                                                                           
 35      {
 36         c=getch();
 37         arr[i]=c;
 38         printf("*");
 39      }
 40      putchar(10);
 41      puts(arr);
 42      return 0;
 43 }

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值