c语言工程建设设计03_输入输出.pptVIP

  • 2
  • 0
  • 约1.81千字
  • 约 30页
  • 2018-08-21 发布于湖北
  • 举报
c语言工程建设设计03_输入输出

* C语言工程设计 杨志钢 zgyang@hrbeu.edu.cn 数据输入输出 标准输出printf 标准输出printf 标准输出printf 标准输出printf 标准输出sprintf 标准输入scanf 标准输入scanf 标准输入scanf D 标准输入scanf 字符的输入输出 字符串的输入输出 scanf(“%s”,…)不接收空格、制表符 而gets能够接收空格、制表符 文件的输入输出 文件的输入输出 文件的输入输出 文件的输入输出 文件的输入输出 #include stdio.h void main() { FILE *fp = fopen(E:\\tmp.txt,r) ; char ch; ch = fgetc(fp); while(ch != EOF) { putchar(ch); ch = fgetc(fp); } } 文件的输入输出 文件的输入输出 文件的输入输出 文件的输入输出 文件的输入输出 文件的输入输出 文件的输入输出 文件的输入输出 文件的输入输出 练习:读取BMP文件信息 图像文件头 (0x00-0x0D,共14 Bytes) typedef struct bmpfileheader_t { unsigned short bfType; /* 文件类型‘BM’=0x4D42 */ unsigned int bfSize; /* 文件大小,字节为单位*/ unsigned short bfRes1; /* 保留,必须设置为0 */ unsigned short bfRes2; /* 保留,必须设置为0 */ unsigned int bfOffBits; /*从文件头开始到实际的图象数据之间的字节的偏移量 */ } bmpfileheader_t; 练习:读取BMP文件头信息 位图信息头 (0x0E-0x35,共40 Bytes) typedef struct bmpinfoheader_t { unsigned int biSize; /*bmpinfoheader_t结构所需要的字数 */ unsigned int biWidth; /*图象的宽度,以象素为单位 */ unsigned int biHeight; /*图象的高度,以象素为单位 */ unsigned short biPlanes; /* 位图的位面数,该值总是1 */ unsigned short biBitCount; /*每个像素的位数,1(单色),4(16色),8(256色),16(64K色,高彩色),24(16M色,真彩色),32(4096M色,增强型真彩色)*/ unsigned int biCompression; /*压缩说明,0(不压缩),1,2,3 */ unsigned int biSizeImage; /*图象的大小,以字节为单位,数值上等于(≥位图宽度的最小的4的倍数)×位图高度×每个像素位数 */ unsigned int biXPelsPerMeter; /*水平分辨率,用象素/米表示*/ unsigned int biYPelsPerMeter; /*垂直分辨率,用象素/米表示*/ unsigned int biClrUsed; /*位图使用的颜色索引,(0:使用所有调色板项)*/ unsigned int biClrImportant; /*对图象显示有重要影响的颜色索引数目,(0:表示都重要)*/ } bmpinfoheader_t; 练习:读取BMP文件头信息 1. 编写程序,读取BMP图像文件头信息,并打印显示 2. 对于biBitCount=8的BMP图像,生成其反色图像。 #includestdio.h #includestdlib.h int main( ) { int a1, a2; char c1, c2; scanf(%d%d,a1,a2); scanf(%c%c,c1,c2); printf(a1=%d\n,a1); printf(a2=%d\n,a2); printf(c1=%c\n,c1); printf(c2=%c\n,c2); return 1; } *

文档评论(0)

1亿VIP精品文档

相关文档