llinux终端输入回显 *
#include <termios.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.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;
while(1)
{
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);
if(c=='\n')
{
putchar(10);
break;
}
printf("*");
assert(res==0);
}
return c;
}
int main()
{
getch();
return 0;
}
改颜色
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
FILE* fp = fopen("1.bmp","r+");
if(fp == NULL){return 0;}
int w=0,h=0;
fseek(fp,18,SEEK_SET);
fread(&w,4,1,fp);
fread(&h,4,1,fp);
fseek(fp,54,SEEK_SET);
char bgr[3][3]={ {255,0,0},
{0,255,0},
{0,0,255}
};
for(int j=0;j<3;j++)
{
for(int i=0;i<h*w/3;i++)
{
fwrite(bgr[j],3,1,fp);
}
}
fclose(fp);
return 0;
}