改变图片色彩————德国国旗
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{FILE* fp=fopen("./haha.bmp","r");int h=0,w=0;fseek(fp,18,SEEK_SET);fread(&w,4,1,fp);fread(&h,4,1,fp);fclose(fp);fp=fopen("./haha.bmp","r+");fseek(fp,54,SEEK_SET);unsigned char pix[3]={0,225,225};for(int i=0;i<w;i++){for(int j=0;j<h/3;j++){fwrite(pix,3,1,fp);}}unsigned char mix[3]={0,0,255};for(int i=0;i<w;i++){for(int j=h/3;j<2*h/3;j++){fwrite(mix,3,1,fp);}}unsigned char lix[3]={0,0,0};for(int i=0;i<w;i++){for(int j=2*h/3;j<h;j++){fwrite(lix,3,1,fp);}}fclose(fp);return 0;
}
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>#include <termios.h>
#include <sys/types.h>
#include <assert.h>int getch()
{int c=0;struct termios org_opts, new_opts;int res=0;res=tcgetattr(STDIN_FILENO, &org_opts);assert(res==0);new_opts = org_opts;new_opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL);tcsetattr(STDIN_FILENO, TCSANOW, &new_opts);c=getchar();res=tcsetattr(STDIN_FILENO, TCSANOW, &org_opts);assert(res==0);return c;
}int main(int argc, const char *argv[])
{printf("请输入密码:");char arr[123456]={0};char c=0;int a=0;while(1){c=getch();if(c=='\n'){break;}else{arr[a]=c;a++;printf("*");}}arr[a]='\0';putchar(10);printf("输入的密码为:");puts(arr);return 0;
}