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