杭州有文化底蕴纪念品:C语言 I/O.h 的函数如何理解

来源:百度文库 编辑:高考问答 时间:2024/04/28 23:21:16
本人是初学者,
关于open,lseek,read,等,这些函数有点难理解.
好心人提点提点。
最好能帮下面的代码加注释.谢谢。

#include "graphics.h"
#include "Svga64k.h"
#include "stdio.h"
#include "fcntl.h"
#include "malloc.h"
#include "io.h"

int huge Return_SVGA64K(void)
{
return(4); /* 返回各种分辨率的对应编号 0~6 宏定义参见 Svga64k.h */
}

typedef struct /*16Mrgb像素类型*/
{unsigned char b;
unsigned char g;
unsigned char r;
}rgb16M;

void putpoint65536(int x,int y,rgb16M color)
{
setrgbpalette(1026,color.r>>3,color.g>>2,color.b>>3);
putpixel(x,y,0);
}

void main()
{int width,height,i=DETECT,j=0,x0,y0,fp;
char fix;
rgb16M *buffer;
installuserdriver("Svga64K",Return_SVGA64K);/*对于svga64k必需执行该函数以安装BGI驱动*/
initgraph(&i,&j,"");/* 执行TC默认的BGI初始化函数 */

if((fp=open("xy_tc.bmp",O_RDONLY|O_BINARY))==-1)
{puts("Can't find file ""xy_tc.bmp"".");
getch();
exit(1);
}
lseek(fp,18,SEEK_SET);
read(fp,&width,4);
read(fp,&height,4);
fix=width%4;
x0=(320-width)/2;y0=(200-height)/2;
lseek(fp,54,SEEK_SET);
buffer=(rgb16M *)malloc(width*sizeof(rgb16M));

for(j=height-1;j>=0;j--)
{read(fp,buffer,width*sizeof(rgb16M));
lseek(fp,fix,SEEK_CUR);
for(i=0;i<width;i++)
putpoint65536(x0+i,y0+j,buffer[i]);
}
free(buffer);
close(fp);
getch();
closegraph();
}

既然是初学,干嘛去研究这些不标准的古董

还是找点比较新的书/程序看看吧
C89 C99多看看

www.huioshj.com

IO.h确实是不标准的,它不能保证在win32环境下使用,所以,不推荐使用,也不值得学了。