C语言编程技巧汇萃(包含大量实用函数)


编程函数集,详细内容如下:

读键盘扫描码
获取机器日期
将浮点数转化为字符串
清除屏幕
显示时间
打印一个矩形
砍掉字符串中所有空格
取子字符串
从文件中读取字符
字符串左靠齐
取左字符串
向文件写数据
取右字符串
打开或关闭光标
喇叭发声
时间延迟
正点报时
写整数于文件中
从文件中读取整数
报警
字符串右靠齐
字符串居中
删除子字符串
查找指定字符串
产生空格
产生字符串
砍掉字符串左边空格
砍掉字符串右边空格
显示一个字符串
定义屏幕颜色
显示提示窗口显示警告窗口
得到文件长度
窗口滚屏
扫描键盘
插入字符串 
检测磁盘是否准备就绪
检测磁盘是否写保护
修改文件的某一行
成批拷贝文件
拷贝一个文件
建立目录
得到目录
得到文件名
任意两个正整数相加(<80位)
任意两个正整数相乘


注意:该函数集省略了不少TC标准头文件,读者使用时要自行添加。而且由于该函数集内部函数间有的有调用关系,读者拆卸时要谨慎。
ExpandedBlockStart.gif ContractedBlock.gif /**/ /*编程技巧荟萃*/
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*从键盘中读取字符 功能:按下普通键时,返回其ASCII码 扫描码CODE=0*/
None.gif
int  INKEY( int   * code)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int m;
ExpandedSubBlockStart.gifContractedSubBlock.gif
while(!bioskey(1))/**//*可加入无按键时代码*/;
InBlock.gif
*code=bioskey(0);
InBlock.gifm
=*code*255;
InBlock.gif
if(!m) m=*code>>8;
InBlock.gif
*code=*code&255;
InBlock.gif
return m;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*获取机器日期*/
None.gif
int  DATE( char   * s, char  type)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
char dat[30];
InBlock.gif
int num;
InBlock.gif
struct tm *tblock;
InBlock.giftime_t t;
InBlock.gift
=time(NULL);
InBlock.giftblock
=localtime(&t);
InBlock.gifstrcpy(dt,asctime(tblock));
InBlock.gifstrcpy(s,
"");
InBlock.gif
switch(type)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
case 'N':
InBlock.gifnum
=(*tblock).tm_year+1900;
InBlock.gifitoa(num,s,
10);
InBlock.gif
break;
InBlock.gif
case 'Y':
InBlock.gifnum
=(*tblock).tm_mon+1;
InBlock.gifitoa(num,s,
10);
InBlock.gif
break;
InBlock.gif
case 'R':
InBlock.gifnum
=(*tblock).tm_mday;
InBlock.gifitoa(num,s,
10);
InBlock.gif
break;
InBlock.gif
case 'S':
InBlock.gifstrcpy(dt,asctime(tblock));
InBlock.gifMID(s,dt,
12,8);
InBlock.gif
break;
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}

None.gif
return  num;
None.gif}
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*将浮点数转化为字符串*/
ExpandedBlockStart.gifContractedBlock.gif
/**/ /* 参数说明 data:需转换的浮点数;s:输出字符串;len:转换后的长度*/
None.gif
void  f_to_s( double  data, char   * s, int  len)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int dec,sign,i;
InBlock.gif
char *s1,s2[100],s3[100];
InBlock.gifs1
=0;
InBlock.gifs2[
0]=0;
InBlock.gifs3[
0]=0;
InBlock.gifs1
=fcvt(data,len,&dec,&sign);
InBlock.gif
if (!sign&&data>=1)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifMID(s2,s1,dec
+1,-1);
InBlock.gifMID(s3,s1,
1,dec);
InBlock.gifstrcpy(s,
"+");
InBlock.gifstrcat(s,s3);
InBlock.gifstrcat(s,
".");
InBlock.gifstrcat(s,s2);
ExpandedSubBlockEnd.gif}

InBlock.gif
if (sign&&fabs(data)>=1)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifMID(s2,s1,dec
+1,-1);
InBlock.gifstrcpy(s,
"-");
InBlock.gifMID(s3,s1,
1,dec);
InBlock.gifstrcat(s,s3);
InBlock.gifstrcat(s,
".");
InBlock.gifstrcat(s,s2);
ExpandedSubBlockEnd.gif}

InBlock.gif
if (!sign&&dec==0)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifstrcpy(s,
"+0.");
InBlock.gifstrcat(s,s1);
ExpandedSubBlockEnd.gif}

InBlock.gif
if (sign&&dec==0)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifstrcpy(s,
"-0.");
InBlock.gifstrcat(s,s1);
ExpandedSubBlockEnd.gif}

InBlock.gif
if (!sign&&dec<0)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifstrcpy(s,
"+0.");
InBlock.gif
for(i=1;i<=fabs(dec);i++)
InBlock.gifstrcat(s,
"0");
InBlock.gifstrcat(s,s1);
ExpandedSubBlockEnd.gif}

InBlock.gif
if (sign&&dec<0)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifstrcpy(s,
"-0.");
InBlock.gif
for(i=1;i<=fabs(dec);i++)
InBlock.gifstrcat(s,
"0");
InBlock.gifstrcat(s,s1);
ExpandedSubBlockEnd.gif}

InBlock.gif
if (strlen(s)>len) s[len]=0;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*清除屏幕*/
None.gif
void  CLSXY( int  color, int  x, int  y, int  xl, int  yl)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int x1,y1;
InBlock.gifunion REGS r;
InBlock.gif
if(x<1||y<1return;
InBlock.gify
--;
InBlock.gifx
--;
InBlock.gify1
=y+yl-1;
InBlock.gifx1
=x+xl-1;
InBlock.gif
if (y1>25||x1>80)
InBlock.gif
return;
ExpandedSubBlockStart.gifContractedSubBlock.gifr.h.ah
=6/**//*子功能号*/
ExpandedSubBlockStart.gifContractedSubBlock.gifr.h.al
=0/**//*滚动行数*/
InBlock.gifr.h.ch
=y;
InBlock.gifr.h.cl
=x;
InBlock.gifr.h.dh
=y1;
InBlock.gifr.h.dl
=x1;
InBlock.gifr.h.bh
=color*16;
InBlock.gifint86(
16,&r,&r);
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*显示时间*/
None.gif
void  display_time( int  color, int  back_color, int  y, int  x)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
static char oldtime[9]="";
InBlock.gif
char newtime[9];
InBlock.gif
if(y<1||x<1return;
InBlock.gifsettextstyle(
1,0,1);
InBlock.gifDATA(newtime,
'S');
InBlock.gifback_color
=7;
InBlock.gif
if(strcmp(newtime,oldtime))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifsetfillstyle(
1,back_color);
InBlock.gifsetcolor(color);
InBlock.gifbar(
535,458,635,475);
InBlock.gifouttextxy(x,y,newtime);
InBlock.gifstrcpy(oldtime,newtime);
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*打印一个矩形*/
None.gif
void  PRINT_KJ( int  x, int  y, int  wide, int  high)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i;
InBlock.gif
for(i=x;i<x+wide;i+=2)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifgotoxy(i,y);
InBlock.gifcprintf(
"");
ExpandedSubBlockEnd.gif}

InBlock.gifgotoxy(x,y
+high);
InBlock.gifcprintf(
"");
InBlock.gifgotoxy(x
+wide,y+high);
InBlock.gifcprintf(
"");
InBlock.gifgotoxy(x,y);
InBlock.gifcprintf(
"");
InBlock.gifgotoxy(x
+wide,y);
InBlock.gifcprintf(
"");
InBlock.gif
for(i=x+2;i<x+wide;i+=2)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifgotoxy(i,y
+high);
InBlock.gifcprintf(
"");
ExpandedSubBlockEnd.gif}

InBlock.gif
for(i=y+1;i<y+high;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifgotoxy(x,i);
InBlock.gifcprintf(
"");
ExpandedSubBlockEnd.gif}

InBlock.gif
for(i=y+1;i<y+high;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifgotoxy(x
+wide,i);
InBlock.gifcprintf(
"");
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*砍掉字符串中所有空格*/
None.gif
void  CUT_ALL_SPC( char   * s)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i,n;
InBlock.gif
char d[10000];
InBlock.gifn
=0;
InBlock.gif
for(i=0;i<strlen(s);i++)
InBlock.gif
if(s[i]!=32)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifd[n]
=s[i];
InBlock.gifn
++;
ExpandedSubBlockEnd.gif}

InBlock.gifd[n]
=0;
InBlock.gifstrcpy(s,d);
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*取子字符串*/
None.gif
void  MID( char   * s, char   * t, int  n, int  m)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i,j,p;
InBlock.gif
if(n<1) n=1;
InBlock.gifi
=strlen(s);
InBlock.gif
if(i<n) m=0;
InBlock.gif
if(m<0) m=i;
InBlock.gif
else m=n+m-1;
InBlock.gif
if(m>i) m=i;
InBlock.gifp
=m-n+1;
InBlock.gif
if(p<0) p=0;
InBlock.gif
for(i=n-1,j=0;i<m;i++,j++)
InBlock.gift[j]
=s[i];
InBlock.gift[p]
=0;
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*从文件中读取字符*/
None.gif
int  READ_STR( char   * s,FILE  * fp)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i=0;
InBlock.gif
if(!fp) return 0;
InBlock.gif
if(fgets(s,10000,fp)) i=1;
InBlock.gifs[strlen(s)
-1]=0;
InBlock.gif
return i;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*字符串左靠齐*/
None.gif
void  MOVE_LEFT( char   * d, char   * s, int  n)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i,l;
InBlock.gifl
=strlen(s);
InBlock.gif
if(n>l) n=l;
InBlock.gif
for(i=0;i<l;i++)
InBlock.gif
*d++=*s++;
InBlock.gif
*d=0;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*取左字符串*/
None.gif
void  LEFT( char   * d, char   * s, int  n)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i,l;
InBlock.gifi
=0;
InBlock.gifl
=strlen(s);
InBlock.gif
if(n>l) n=l;
InBlock.gif
for(i=0;i<n;i++)
InBlock.gifd[i]
=s[i];
InBlock.gifd[n]
=0;
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*向文件写数据*/
None.gif
void  WRITE_STR( char   * s,FILE  * fp)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
char c=10;
InBlock.gif
if(!fp) return;
InBlock.giffputs(s,fp);
InBlock.giffputc(c,fp);
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*取右字符串*/
None.gif
void  RIGHT( char   * dest, char   * source, int  num)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i,j;
InBlock.gif
if (num<1) num=0;
InBlock.gifnum
=strlen(source)-num;
InBlock.gif
if (num<0) num=0;
InBlock.gif
for(i=0,j=num;j<=strlen(source);i++,j++) dest[i]=source[j];
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*打开或关闭光标*/
None.gif
void  CURSOR( int  on2off)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifunion REGS r;
InBlock.gif
if (on2off!=OFF) on2off=10;
InBlock.gifr.h.ah
=1;
InBlock.gifr.h.ch
=3;
InBlock.gifr.h.cl
=on2off;
InBlock.gifint86(
16,&r,&r);
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*喇叭发声*/
None.gif
void  SOUND( int  frequency, int  time)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i;
InBlock.gifi
=time*50;
InBlock.gif
if (i>30000) i=30000;
InBlock.gif
if (i<50) i=50;
InBlock.gifsound(frequency);
InBlock.gifMYDELAY(i);
InBlock.gifnosound();
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*时间延迟*/
None.gif
void  MYDELAY( long  t)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.giftime_t OldTime;
InBlock.gif
long t0;
InBlock.gift0
=t/55;
InBlock.gif
if (t0<1) t0=1;
InBlock.gifOldTime
=clock();
InBlock.gif
while(clock()-OldTime<t0);
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*正点报时*/
None.gif
void  REPORT_CLOCK( void )
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i;
InBlock.gif
for(i=0;i<5;i++);
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifSOUND(
500,10);
InBlock.gifMYDELAY(
1000);
ExpandedSubBlockEnd.gif}

InBlock.gifSOUND(
800,10);
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*写整数于文件中*/
None.gif
void  WRITE_INT( int  num,FILE  * p)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
char s[20],a=10;
InBlock.gif
if (!p) return;
InBlock.gifitoa(num,s,
10);
InBlock.giffputs(s,p);
InBlock.giffputc(a,p);
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*从文件中读取整数*/
None.gif
int  READ_INT( int   * num,FILE  * p)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i;
InBlock.gif
char s[30]="";
InBlock.gif
if (!p) return 0;
InBlock.gif
if (fgets(s,10000,p))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifi
=-1;
InBlock.gifs[strlen(s)
-1]=0;
InBlock.gif
*num=atoi(s);
ExpandedSubBlockEnd.gif}

InBlock.gif
else i=0;
InBlock.gif
return i;
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*报警 */
None.gif
void  WARN( void )
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifSOUND(
300,1);
InBlock.gifSOUND(
100,1);
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*字符串右靠齐*/
None.gif
void  MOVE_RIGHT( char   * s, int  wide)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i,l,n;
InBlock.gifl
=strlen(s);
InBlock.gifn
=wide-l;
InBlock.gif
if (n>0)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
for(i=l;i>-1;i--) s[i+n]=s[i];
InBlock.gif
for(i=0;i<n;i++) s[i]=32;
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*字符串居中*/
None.gif
void  MOVE_MIDDLE( char   * s, int  wide)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i,l,n;
InBlock.gifl
=strlen(s);
InBlock.gif
if (wide>l)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifwide
=wide-1;
InBlock.gifn
=wide/2;
InBlock.gifwide
=wide-n;
InBlock.gif
for(i=l;i>-1;i--) s[i+n]=s[i];
InBlock.gif
for(i=0;i<n;i++) s[i]=32;
InBlock.gif
for(i=0;i<wide;i++) s[l+n+i]=32;
InBlock.gifs[l
+n+i]=0;
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*删除子字符串*/
None.gif
void  Delete_SubString( char   * source, int  start, int  num)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i,l;
InBlock.gifl
=strlen(source);
InBlock.gif
if (num>l-start+1||num==-1) num=l-start+1;
InBlock.gif
if (start<1||start>1return;
InBlock.gif
for(i=start;i<l-num+2;i++)
InBlock.gifsource[i
-1]=source[i+num-1];
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*查找指定字符串*/
None.gif
int  INSTR( int  n, char   * source, char   * dest)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i,j,k1,k2,p;
InBlock.gif
int start=0;
InBlock.gif
if (n==0) n=1;
InBlock.gifk1
=strlen(source);
InBlock.gifk2
=strlen(dest);
InBlock.gif
if (n<0)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
char s[100];
InBlock.gifn
=-n;
InBlock.gifMID(s,source,n,k2);
InBlock.gif
if (strcmp(s,dest)) return 0;
InBlock.gif
return n;
ExpandedSubBlockEnd.gif}

InBlock.gif
if (k1-n+1<k2) return start;
InBlock.gif
for(i=n-1;i<k1;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifp
=0;
InBlock.gif
for(j=0;j<k2;j++)
InBlock.gif
if (source[i+j]!=dest[j]) break;
InBlock.gif
else p++;
InBlock.gif
if (p==k2)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifstart
=i+1;
InBlock.gif
break;
ExpandedSubBlockEnd.gif}

ExpandedSubBlockEnd.gif}

InBlock.gif
return start;
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*产生空格*/
None.gif
void  SPACE( char   * s, int  n)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i;
InBlock.gif
if (n<0) n=0;
InBlock.gif
for(i=0;i<n;i++*s++=32;
InBlock.gif
*s=0;
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*产生字符串*/
None.gif
void  STRING( int  n, char   * s1, char   * s2)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i;
InBlock.gif
if (n<0) n=0;
InBlock.gifs1[
0]=0;
InBlock.gif
for(i=1;i<=n;i++) strcat(s1,s2);
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*砍掉字符串左边空格*/
None.gif
void  CUT_LEFT_SPACE( char   * s)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i,j,k=0;
InBlock.gifi
=strlen(s)+1;
InBlock.gif
for(j=0;j<i;j++if (s[j]!=' 'break;
InBlock.gif
for(k=0;j<i;k++,j++) s[k]=s[j];
ExpandedBlockEnd.gif}

None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*砍掉字符串右边空格*/
None.gif
void  CUT_RIGHT_SPACE( char   * s)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int i,j;
InBlock.gifi
=strlen(s)-1;
InBlock.gif
for(j=i;j>-1;j--if (s[j]!=' 'break;
InBlock.gifs[j
+1]=0;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*显示一个字符串*/
None.gif
void  DISPLAY( char   * s)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifunion REGS regs;
InBlock.gif
int color,x,y;
InBlock.gifx
=wherex();
InBlock.gify
=wherey();
InBlock.gifcolor
=16*bjys+qjys;
InBlock.gif
while(*s)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
if(x>80break;
InBlock.gifregs.h.ah
=9;
InBlock.gifregs.h.al
=*s;
InBlock.gifregs.h.bh
=0;
InBlock.gifregs.h.bl
=color;
ExpandedSubBlockStart.gifContractedSubBlock.gifregs.x.cx
=1/**//*显示的次数,不改变光标位置*/
InBlock.gifint86(
16,®s,®s);
InBlock.gifx
++;
InBlock.gif
if(x>80)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifx
=1;
InBlock.gify
++;
InBlock.gif
if(y>25) y=25;
ExpandedSubBlockEnd.gif}

InBlock.gifgotoxy(x,y);
InBlock.gifs
++;
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*定义屏幕颜色*/
None.gif
void  COLOR( int  ForeColor, int  BackColor)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
if(ForeColor<0||ForeColor>15return;
InBlock.gif
if(BackColor<0||BackColor>15return;
InBlock.gifqjys
=ForeColor;
InBlock.gifbjys
=BackColor;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*显示提示窗口*/
None.gif
void  quit_YesNo( char   * s1, char   * s2)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
char buffer[2000],jx;
InBlock.gifgettext(
30,8,76,16,buffer);
InBlock.giftextbackground(
3);
InBlock.gifCLSXY(
8,32,9,30,6);
InBlock.gifCLSXY(
4,30,8,30,6);
InBlock.gifCOLOR(
15,4);
InBlock.gifgotoxy(
35,10);
InBlock.gifDISPLAY(s1);
InBlock.gifgotoxy(
35,12);
InBlock.gifDISPLAY(s2);
InBlock.gifgotoxy(
35+strlen(s2)+1,12);
InBlock.gifjx
=getch();
InBlock.gifputtext(
30,8,76,16,buffer);
InBlock.gif
if (jx=='n'||jx=='N'return;
InBlock.giftextbackground(
0);
InBlock.giftextcolor(
15);
InBlock.gifclrscr();
InBlock.gifCURSOR(ON);
InBlock.gifexit(
0);
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*显示警告窗口*/
None.gif
void  warn_message( char   * s1, char   * s2)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
char buffer[2000];
InBlock.gifgettext(
30,8,76,16,buffer);
InBlock.gifCLSXY(
8,32,9,30,6);
InBlock.gifCLSXY(
4,30,8,30,6);
InBlock.gifCOLOR(
15,4);
InBlock.gifgotoxy(
35,10);
InBlock.gifDISPLAY(s1);
InBlock.gifgotoxy(
35,12);
InBlock.gifDISPLAY(s2);
InBlock.gifgotoxy(
40,13);
InBlock.gifDISPLAY(
"按任意键继续dot.gif");
InBlock.gifgetch();
InBlock.gifputtext(
30,8,76,16,buffer);
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*得到文件长度*/
None.gif
long  GetFileLength( char   * file)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifFILE 
*fp;
InBlock.gif
int i;
InBlock.gif
if ((fp=fopen(file,"rb"))==NULL)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifclrscr();
InBlock.gifprintf(
"Can't open the file %s .",file);
InBlock.gif
return 0;
ExpandedSubBlockEnd.gif}

InBlock.gifi
=0;
InBlock.gif
while(!feof(fp))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifi
++;
InBlock.giffgetc(fp);
ExpandedSubBlockEnd.gif}

InBlock.giffclose(fp);
InBlock.gif
return (i-1);
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*窗口滚屏*/
None.gif
void  WINDOW_ROLL( int  y1, int  x1, int  yl, int  xl, int  direct)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifunion REGS regs;
InBlock.gif
int x2,y2;
InBlock.gifx1
--;
InBlock.gify1
--;
InBlock.gifx2
=x1+xl-1;
InBlock.gify2
=y1+yl-1;
ExpandedSubBlockStart.gifContractedSubBlock.gifregs.h.ah
=5+direct; /**//*ah=06h 向上滚动当前页*/
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//*ah=07h 向下。。。 */
InBlock.gifregs.h.al
=1;
InBlock.gifregs.h.bh
=16*pmbj+pmqj;
ExpandedSubBlockStart.gifContractedSubBlock.gifregs.h.ch
=y1; /**//*左上角行*/
ExpandedSubBlockStart.gifContractedSubBlock.gifregs.h.cl
=x1; /**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gifregs.h.dh
=y2; /**//*右下角行*/
ExpandedSubBlockStart.gifContractedSubBlock.gifregs.h.dl
=x2; /**//**/
InBlock.gifint86(
16,®s,®s);
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*扫描键盘*/
None.gif
int  scan_keyboard( int   * m)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifunion inkey
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifunsigned 
char ch[2];
InBlock.gif
int ii;
ExpandedSubBlockEnd.gif}
cc;
InBlock.gif
while(!bioskey(1))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{;}
InBlock.gifcc.ii
=bioskey(0);
InBlock.gif
*m=cc.ch[1];
InBlock.gif
return cc.ch[0];
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*插入字符串*/
None.gif
void  INSERT_STRING( char   * ds, char   * ss, int  n)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
char s[100];
InBlock.gifMID(ds,s,n,
-1);
InBlock.gifds[n
-1]=0;
InBlock.gifstrcat(ds,ss);
InBlock.gifstrcat(ds,s);
ExpandedBlockEnd.gif}

None.gif
void  STR_ADD_CHAR( char   * s, char  ch)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
char s1[2];
InBlock.gifs1[
0]=ch;
InBlock.gifs1[
1]=0;
InBlock.gifstrcat(s,s1);
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*检测磁盘是否准备就绪*/
None.gif
int  CheckDiskReading( int  n)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int result;
InBlock.gif
char buffer[512];
InBlock.gifresult
=biosdisk(4,n,0,0,0,1,buffer);
InBlock.gifresult
=result&0x02;
InBlock.gif
if (result!=0x02return 0;
InBlock.gif
return 1;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*检测磁盘是否写保护*/
None.gif
int  CheckDiskWriteProf( void )
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int result;
InBlock.gif
char buffer[512];
InBlock.gifresult
=biosdisk(5,0,0,0,0,1,buffer);
InBlock.gif
if (result==0x03return 0;
InBlock.gif
return 1;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*修改文件的某一行*/
None.gif
int  ModifyFileLine( char   * filename, char   * s, int  n)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
char data[20][80];
InBlock.gif
int i;
InBlock.gifFILE 
*fp;
InBlock.gif
if ((fp=fopen(filename,"r"))==NULL) return 0;
InBlock.gifi
=0;
InBlock.gif
while(READ_STR(data[i],fp))
InBlock.gifi
++;
InBlock.giffclose(fp);
InBlock.giffp
=fopen(filename,"w");
InBlock.gifstrcpy(data[n
-1],s);
InBlock.gifn
=i-1;
InBlock.gif
for(i=0;i<=n;i++)
InBlock.gifWRITE_STR(data[i],fp);
InBlock.giffclose(fp);
InBlock.gif
return 1;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*成批拷贝文件*/
None.gif
int  CopyFile( char   * sfile, char   * dfile, int  f2d, int  barlong, int  height, int  x, int  y)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
int Copyfile(char *sf,char *df);
InBlock.gif
int MakeNdir(char *Dir);
InBlock.gif
char filename[200][13],d[40],s[40],s1[40];
InBlock.gif
struct ffblk ffblk;
InBlock.gif
int done,i,j,l,len;
InBlock.gifi
=0;
InBlock.gifdone
=findfirst(sfile,&ffblk,0);
InBlock.gif
if (!done) strcpy(filename[i],ffblk.ff_name);
InBlock.gif
while(!done)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifdone
=findnext(&ffblk);
InBlock.gif
if (!done)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifi
++;
InBlock.gifstrcpy(filename[i],ffblk.ff_name);
ExpandedSubBlockEnd.gif}

ExpandedSubBlockEnd.gif}

InBlock.gif
if (f2d)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifCopyfile(sfile,dfile);
InBlock.gif
return 1;
ExpandedSubBlockEnd.gif}

InBlock.gifstrcpy(s,sfile);
InBlock.gifl
=strlen(sfile);
InBlock.gif
for(j=l-1;j>=0;j--)
InBlock.gif
if (s[j]=='\\')
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifs[j
+1]=0;
InBlock.gif
break;
ExpandedSubBlockEnd.gif}
 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//*拷贝一个文件*/
InBlock.gif
int Copyfile(char *sf,char *df)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifFILE 
*in,*out;
InBlock.gif
char ch;
InBlock.gif
in=0;
InBlock.gif
out=0;
InBlock.gif
if ((in=fopen(sf,"rb"))==NULL)
InBlock.gifexit(
0);
InBlock.gif
if ((out=fopen(df,"wb"))==NULL)
InBlock.gifexit(
0);
InBlock.gif
while(!feof(in))
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifch
=fgetc(in);
InBlock.gif
if (ferror(in)) return 0;
InBlock.giffputc(ch,
out);
InBlock.gif
if (ferror(out)) return 0;
ExpandedSubBlockEnd.gif}

InBlock.giffclose(
in);
InBlock.giffclose(
out);
InBlock.gif
return 1;
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//*建立目录*/
InBlock.gif
int MakeNdir(char *Dir)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
int i,l,j;
InBlock.gif
char s[10][40];
InBlock.gifj
=0;
InBlock.gifl
=strlen(Dir);
InBlock.gif
for(i=0;i<l;i++)
InBlock.gif
if (Dir[i]=='\\')
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifLEFT(s[j],Dir,i);
InBlock.gifj
++;
ExpandedSubBlockEnd.gif}

InBlock.gifstrcpy(s[j],Dir);
InBlock.gif
for(i=0;i<=j;i++)
InBlock.gif
if (access(s[i],0)) mkdir(s[i]);
InBlock.gif
return 1;
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//*得到目录*/
InBlock.gif
int GetDir(char *dirF,char dataK[][14])
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
struct ffblk ffblk;
InBlock.gif
int done;
InBlock.gif
int i;
InBlock.gifi
=0;
InBlock.gifdone
=findfirst(dirF,&ffblk,FA_DIREC);
InBlock.gif
while(!done)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
if (ffblk.ff_attrib==16||ffblk.ff_attrib==17)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifstrcpy(dataK[i],ffblk.ff_name);
InBlock.gifstrcat(dataK[i],
"\\");
InBlock.gifi
++;
ExpandedSubBlockEnd.gif}

InBlock.gifdone
=findnext(&ffblk);
ExpandedSubBlockEnd.gif}

InBlock.gif
return i;
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//*得到文件名*/
InBlock.gif
int GetFile(char *dirF,char dataK[][14])
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
struct ffblk ffblk;
InBlock.gif
int done;
InBlock.gif
int i;
InBlock.gifi
=0;
InBlock.gifdone
=findfirst(dirF,&ffblk,0);
InBlock.gif
while(!done)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifstrcpy(dataK[i],ffblk.ff_name);
InBlock.gifdone
=findnext(&ffblk);
InBlock.gifi
++;
ExpandedSubBlockEnd.gif}

InBlock.gif
return i;
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//*任意两个正整数相加(<80位)*/
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//*参数说明:numA,numB分别为加数和被加数,result存放相加后的结果*/
InBlock.gif
void add(char *numA,char *numB,char *result)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
int i,j,a,b,c,jw,Alen,Blen; /**//*定义变量*/
InBlock.gif
char num[81];
ExpandedSubBlockStart.gifContractedSubBlock.gif
char numC[81]; /**//*定义新的字串,长度与numA相同*/
InBlock.gif
char ch;
InBlock.gif
char s[1];
InBlock.gifnum[
0]=0;
InBlock.gifnumC[
0]=0;
InBlock.gif
if (strlen(numA)>=80return;
InBlock.gif
if (strlen(numB)>=80return;
ExpandedSubBlockStart.gifContractedSubBlock.gif
for(i=0;i<strlen(numA);i++/**//*判断输入数是否非法*/
ExpandedSubBlockStart.gifContractedSubBlock.gif
if (!isdigit(numA[i])) return/**//*如果非法返回结果为空*/
InBlock.gif
for(i=0;i<strlen(numB);i++)
InBlock.gif
if (!isdigit(numB[i])) return;
ExpandedSubBlockStart.gifContractedSubBlock.gif
if (strlen(numA)<strlen(numB)) /**//*将较大的数放入numA中*/
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifstrcpy(num,numA);
InBlock.gifstrcpy(numA,numB);
InBlock.gifstrcpy(numB,num);
InBlock.gifnum[
0]=0;
ExpandedSubBlockEnd.gif}

InBlock.gifAlen
=strlen(numA);
InBlock.gifBlen
=strlen(numB);
InBlock.gifstrcpy(numC,numB);
InBlock.gif
for(i=0;i<Alen;i++)
InBlock.gifnumC[Alen
-i-1]=numC[Blen-i-1];
ExpandedSubBlockStart.gifContractedSubBlock.gif
for(i=0;i<Alen-Blen;i++/**//*在numC中插入n个0,使其长度等于numA*/
InBlock.gifnumC[i]
='0';
ExpandedSubBlockStart.gifContractedSubBlock.gifjw
=0/**//*进位*/
InBlock.gif
for(i=0;i<Alen;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifs[
0]=numA[Alen-i-1];
InBlock.gifs[
1]=0;
InBlock.gifa
=atoi(s);
InBlock.gifs[
0]=numC[Alen-i-1];
InBlock.gifs[
1]=0;
InBlock.gifb
=atoi(s);
InBlock.gifc
=a+b+jw;
InBlock.gif
if (c>=10)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifjw
=1;
InBlock.gifc
=c-10;
ExpandedSubBlockEnd.gif}

InBlock.gif
else jw=0;
InBlock.gifitoa(c,s,
10);
InBlock.gifnum[i]
=s[0];
ExpandedSubBlockEnd.gif}

ExpandedSubBlockStart.gifContractedSubBlock.gif
if (jw==1dot.gif{num[i]='1';num[i+1]=0;}
InBlock.gif
else num[i]=0;
InBlock.gifj
=strlen(num);
InBlock.gif
for(i=0;i<j/2;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifch
=num[i];
ExpandedSubBlockStart.gifContractedSubBlock.gifnum[i]
=num[j-i-1]; /**//*将num反转*/
InBlock.gifnum[j
-i-1]=ch;
ExpandedSubBlockEnd.gif}

InBlock.gifstrcpy(result,num);
ExpandedSubBlockStart.gifContractedSubBlock.gif
return/**//*返回相加结果*/
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//*任意两个正整数相乘*/
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//*参数说明:numA,numB 分别为乘数和被乘数,resultm存放积*/
InBlock.gif
void mult(char *numA,char *numB,char *resultm)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
int i,j,k,l,m,a,b,c,jw,Alen,Blen,f; /**//*定义变量*/
InBlock.gif
char resulta[82];
InBlock.gif
char num[161];
InBlock.gif
char ch;
InBlock.gif
char s[1];
InBlock.gifnum[
0]=0;
InBlock.giff
=0;
InBlock.gif
if (strlen(numA)>=80return;
InBlock.gif
if (strlen(numB)>=80return;
ExpandedSubBlockStart.gifContractedSubBlock.gif
for(i=0;i<strlen(numA);i++/**//*判断输入数是否非法*/
ExpandedSubBlockStart.gifContractedSubBlock.gif
if (!isdigit(numA[i])) return/**//*如果非法返回结果为空*/
InBlock.gif
for(i=0;i<strlen(numB);i++)
InBlock.gif
if (!isdigit(numB[i])) return;
ExpandedSubBlockStart.gifContractedSubBlock.gif
if (strlen(numA)<strlen(numB)) /**//*将较大的数放入numA中*/
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifstrcpy(num,numA);
InBlock.gifstrcpy(numA,numB);
InBlock.gifstrcpy(numB,num);
InBlock.gifnum[
0]=0;
ExpandedSubBlockEnd.gif}

InBlock.gifAlen
=strlen(numA);
InBlock.gifBlen
=strlen(numB);
InBlock.gifstrcpy(resultm,
"0");
InBlock.gif
for(i=0;i<Blen;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifs[
0]=numB[Blen-i-1];
InBlock.gifs[
1]=0;
InBlock.gifc
=atoi(s);
InBlock.gifstrcpy(resulta,numA);
InBlock.gif
if (c==0) strcpy(resulta,"0");
ExpandedSubBlockStart.gifContractedSubBlock.gif
for(j=0;j<c-1;j++dot.gif{add(resulta,numA,resulta);}
InBlock.gifl
=strlen(resulta);
InBlock.gif
for(k=0;k<i;k++)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifresulta[l
+k]='0';
InBlock.gifresulta[l
+k+1]=0;
ExpandedSubBlockEnd.gif}

InBlock.gifadd(resultm,resulta,resultm);
ExpandedSubBlockEnd.gif}

ExpandedSubBlockEnd.gif}

转载于:https://www.cnblogs.com/zhangyin/archive/2007/02/15/650870.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值