untitled

Similar documents
C 1

untitled

CC213

epub 33-8

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

新・明解C言語入門編『索引』

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9

第3章.doc

C++ 程式設計

Generated by Unregistered Batch DOC TO PDF Converter , please register! 浙江大学 C 程序设计及实验 试题卷 学年春季学期考试时间 : 2003 年 6 月 20 日上午 8:3

<4D F736F F D20D7DBBACFCAD4CCE231B2CEBFBCB4F0B0B82E646F63>

ebook15-C

[改訂新版]C言語による標準アルゴリズム事典

C/C++语言 - C/C++数据

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

Microsoft Word - 实用案例.doc

FY.DOC

C

第7章-并行计算.ppt

C/C++ 语言 - 循环

新版 明解C++入門編


ebook39-5

untitled

c_cpp

C/C++语言 - 分支结构

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit

2013 C 1 #include <stdio.h> 2 int main(void) 3 { 4 int cases, i; 5 long long a, b; 6 scanf("%d", &cases); 7 for (i = 0; i < cases; i++) 8 { 9 scanf("%

CC213

C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha

C语言的应用.PDF






nooog

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

untitled

_汪_文前新ok[3.1].doc

static struct file_operations gpio_ctl_fops={ ioctl: gpio_ctl_ioctl, open : gpio_open, release: gpio_release, ; #defineled1_on() (GPBDAT &= ~0x1) #def

3. 給 定 一 整 數 陣 列 a[0] a[1] a[99] 且 a[k]=3k+1, 以 value=100 呼 叫 以 下 兩 函 式, 假 設 函 式 f1 及 f2 之 while 迴 圈 主 體 分 別 執 行 n1 與 n2 次 (i.e, 計 算 if 敘 述 執 行 次 數, 不

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

chap07.key

全国计算机技术与软件专业技术资格(水平)考试

mvc

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

C6_ppt.PDF

Microsoft PowerPoint - os_4.ppt

第一章

Microsoft Word - C-pgm-ws2010.doc

2013年全国农村妇女科学素质网络竞赛活动总结

“秦火火”玩“火”自焚

2014年9月月讯

1

<4D F736F F D C4EAD6D0BFBCD3EFCEC4C6C0BCDBD6B8C4CFA3A8B6A8B8E5A3A92E646F63>

目 录

Transcription:

1 DBF (READDBF.C)... 1 2 (filetest.c)...2 3 (mousetes.c)...3 4 (painttes.c)...5 5 (dirtest.c)...9 6 (list.c)...9

1 dbf (readdbf.c) /* dbf */ #include <stdio.h> int rf,k,reclen,addr,*p1; long brec,erec,i,j,recnum,*p2; unsigned char buf[4096],pbuf[81]; FILE *fp; main(int argc,char *argv[]) if (argc==1) printf("usage:\n"); exit(0); fp=fopen(argv[1],"rb"); if (fp==null) printf("%s can not open\n", argv[1]); exit(0); fread(buf,1,32,fp); p1=(int *)buf; p2=(long *)buf; p2++; recnum= *p2; p1+=4; addr= *p1; p1++; reclen= *p1; if (argc==2) rf=0; brec=1; erec=recnum; if (argc==3) rf=atoi(argv[2]); brec=1; erec=recnum; if (argc==4) rf=atoi(argv[2]); brec=atoi(argv[3]); erec=recnum; 1

if (argc==5) rf=atoi(argv[2]); brec=atoi(argv[3]); erec=atoi(argv[4]); fseek(fp,(long)addr-32,1); for (i=1; i<erec; i++) fread(buf,1,reclen,fp); buf[reclen]='\0'; if (i>=brec && i<=erec) if (rf!=0) printf("rec no: %d\n", i); for(j=0; j<=reclen;) for(k=0; k<80; ) pbuf[k++]=buf[j++]; pbuf[80]='\0'; printf("%s",pbuf); printf("\n"); fclose(fp); 2 (filetest.c) /* */ #include <stdio.h> void sort(int *list, int n) int i,j,next; for(i=1; i<n; i++) next=list[i]; for(j=i-1;j>=0 && next<list[j]; j--) list[j+1]=list[j]; list[j+1]=next; main() int input[10], i; FILE *fpin, *fpout; 2

if ((fpin=fopen("in.dat", "r"))==null) printf("can not open file in.dat\n"); exit(-1); for(i=0; i<10; i++) fscanf(fpin, "%d", &input[i]); /* fread(input, sizeof(int), 10, fpin); */ sort(input, 10); if ((fpout=fopen("out.dat", "w"))==null) printf("can not open file in\n"); exit(-1); for(i=0; i<10; i++) fprintf(fpout, "%d ", input[i]); /* fwrite(input, sizeof(int), 10, fpout); */ printf("\n"); 3 (mousetes.c) /* */ #include <dos.h> #define ON 1 #define OFF 2 #define LEFTBUTTON 1 #define RIGHTBUTTON 2 #define BOTHBUTTON 3 int havemouse=0; int resetmouse() r.x.ax=0; int86(0x33, &r, &r); havemouse=r.x.ax; return havemouse==0? 0 : r.x.bx; void lightmouse(int op) 3

if (havemouse) r.x.ax=op; int86(0x33, &r,&r); int getmousestatus(int *x, int *y) if (havemouse) r.x.ax=3; int86(0x33, &r, &r); *x= r.x.cx; *y= r.x.dx; return r.x.bx; else return 0; void setmousexy(int x, int y) if (havemouse) r.x.ax=4; r.x.cx=x; r.x.dx=y; void setmouserange(int left, int top, int right, int bottom) if (havemouse) r.x.ax=7; r.x.cx=left; r.x.dx=right; 4

r.x.ax=8; r.x.cx=top; r.x.dx=bottom; main() int button, x, y n; if (!(n=resetmouse())) printf("no Mouse\n"); exit(0); else printf("yes:%d\n",n); lightmouse(on); setmouserange(50,50,100,100); do button=getmousestatus(&x,&y); if (button==leftbutton) printf("leftbutton\n"); else if (button==rightbutton) printf(" RIGHTBUTTON\n"); while (button!=bothbutton); lightmouse(off); 4 (painttes.c) /* */ #include <stdio.h> #include <dos.h> #include <graphics.h> /* ----------------- */ #define ON 1 #define OFF 2 #define LEFTBUTTON 1 #define RIGHTBUTTON 2 #define BOTHBUTTON 3 int havemouse=0; int resetmouse() 5

r.x.ax=0; int86(0x33, &r, &r); havemouse=r.x.ax; return havemouse==0? 0 : r.x.bx; void lightmouse(int op) if (havemouse) r.x.ax=op; int86(0x33, &r,&r); int getmousestatus(int *x, int *y) if (havemouse) r.x.ax=3; int86(0x33, &r, &r); *x= r.x.cx; *y= r.x.dx; return r.x.bx; else return 0; void setmousexy(int x, int y) if (havemouse) r.x.ax=4; r.x.cx=x; r.x.dx=y; 6

void setmouserange(int left, int top, int right, int bottom) if (havemouse) r.x.ax=7; r.x.cx=left; r.x.dx=right; r.x.ax=8; r.x.cx=top; r.x.dx=bottom; /* ------------- */ int mousein(int mx, int my, int x, int y, int width, int height) return (mx>=x) && (mx<x+width) && (my>=y) && (mx<y+height); main() int mode=vgahi; int driver=vga; int color=white; int fillcolor=white; int x,y,button,i; initgraph(&driver, &mode, "c:\tc"); rectangle(0,429,639,479); moveto(10,440); outtext("line Color"); moveto(10,460); outtext("fill Color"); for(i=0; i<16; i++) rectangle(100+i*25,435,124+i*25,475); setfillstyle(1,i); bar(101+i*25,436,123+i*25,474); 7

line(100,455,499,455); moveto(505,440); setcolor(1); outtext("linewidth:1"); bar(600,435,630,455); moveto(505,460); setcolor(2); outtext("linewidth:3"); bar(600,456,630,476); setcolor(white); resetmouse(); lightmouse(on); while(1) button=getmousestatus(&x, &y); if (button==leftbutton) if (mousein(x,y,0,429,639,50)) if (mousein(x,y,100,435,400,20)) color=(x-100)/25; setcolor(color); if (mousein(x,y,100,455,400,20)) fillcolor=(x-100)/25; setfillstyle(1,fillcolor); if (mousein(x,y,600,435,30,20)) setlinestyle(0,0,1); outtext("1"); if (mousein(x,y,600,456,30,20)) setlinestyle(0,0,3); outtext("3"); /* if (mousein(x,y,550,456,75,14)) outtext("out"); break; */ else lightmouse(off); lineto(x,y); lightmouse(on); 8

else if (button==rightbutton) lightmouse(off); setviewport(0,0,639,428,1); floodfill(x,y,color); setviewport(0,0,639,479,1); lightmouse(on); else if (button==bothbutton) break; else moveto(x,y); closegraph(); 5 (dirtest.c) /* */ #include <stdio.h> #include <dir.h> main() struct ffblk ffblk; int done; printf("directory listing of *.c with odd size:\n"); done=findfirst("*.c", &ffblk, 0); while(!done) if (ffblk.ff_fsize % 2) printf(" %s %ld\n", ffblk.ff_name,ffblk.ff_fsize); done=findnext(&ffblk); 6 (list.c) /* */ #include <stdio.h> #include <alloc.h> main() 9

int n,i, data; struct node int data; struct node *next; *head=null, *p, *q1, *q2; scanf("%d", &n); for(i=0; i<n; i++) scanf("%d", &data); p=(struct node *)malloc(sizeof(struct node)); p->data= data; q1=null; q2=head; while ((q2!=null) && (p->data > q2->data)) q1=q2; q2=q2->next; p->next=q2; if (q1!=null) q1->next=p; else head=p; for(p=head; p!=null; p=p->next) printf("%d,", p->data); 10