⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cexam.mdb

📁 不用说了!看看就明白了!
💻 MDB
📖 第 1 页 / 共 2 页
字号:
==========
access
参数说明:
filename指向被访问的文件名,mode决定access()函数去做什么,它的合法值为:
0 检查文件是否存在
1 检查文件是否可运行
2 检查文件是否可以定访问
4 检查是否可以读访问
6 检查是否可以读/写访问
当允许做指定的访问时,返回0否则返回-1
程序例: 
#include <stdio.h> 
#include <io.h> 

int file_exists(char *filename); 

int main(void) 
{ 
  printf("Does NOTEXIST.FIL exist: %s\n", 
  file_exists("NOTEXISTS.FIL") ? "YES" : "NO"); 
  return 0; 
} 

int file_exists(char *filename) 
{ 
  return (access(filename, 0) == 0);
==========
==========
cgets
参数说明:
函数cgets()从控制台读入一字符串以及字符串的长度存入由str所指向的地址中,cgets从控制台读字符,直到控制台输入回车符或已读入的字符超过字符串最大允许的长度为止。在调用该函数前,必须事先给定该字符串的最大允许长度并存入str[0],返回时str[1]被设置为实际读入的字符数,字符串实际的内容从str[2]开始,字符串的未尾用'\0'来结尾。因此,str的实际长度到少为str[0]+2个字节
程序例: 

#include <stdio.h> 
#include <conio.h> 

int main(void) 
{ 
   char buffer[83]; 
   char *p; 

   /* There's space for 80 characters plus the NULL terminator */ 
   buffer[0] = 81; 

   printf("Input some chars:"); 
   p = cgets(buffer); 
   printf("\ncgets read %d characters: \"%s\"\n", buffer[1], p); 
   printf("The returned pointer is %p, buffer[0] is at %p\n", p, &buffer); 

   /* Leave room for 5 characters plus the NULL terminator */ 
   buffer[0] = 6; 

   printf("Input some chars:"); 
   p = cgets(buffer); 
   printf("\ncgets read %d characters: \"%s\"\n", buffer[1], p); 
   printf("The returned pointer is %p, buffer[0] is at %p\n", p, &buffer); 
   return 0; 
}
==========
==========
_chmod
这个函数不是ANSI标准定义的,它用来读取或设置filename指向的文件所连接的DOS系统认可的属性字节。若get_set为0,_chmod()返回当前文件的属性,这时不使用参数attrib,若get_set为1,该文件的属性被设置为attrib的值,attrib的值可以是下列宏之一(这些宏在dos.h)中定义:
FA_RDONLE 标为只读文件
FA_HIDDEN  标为隐含文件
FA_SYSTEM  标为系统文件

例子:
#include <io.h>
#include <sys\stat.h>
#include <dos.h>
main()
{if (_chmod("test.tst",1,FA_RDONLY)==FA_RDONLY)
printf("file set to read only mode");
else
printf("file set to unsuccessfully");
}
==========
==========
chmod
说明:chmod()原原型在io.h中
它把filename指向的访问模式改为mode所指定的模式,mode的值必须是S_IWRITE或S_IREAD两者或其中之一,它们代表写访问和读访问,要把文件的模式设置为读/写状态时,调用的chmod()中的mode设置应写为S_IWRITE|S_IREAD。
程序例: 

#include <sys\stat.h> 
#include <stdio.h> 
#include <io.h> 

void make_read_only(char *filename); 

int main(void) 
{ 
   make_read_only("NOTEXIST.FIL"); 
   make_read_only("MYFILE.FIL"); 
   return 0; 
} 

void make_read_only(char *filename) 
{ 
   int stat; 

   stat = chmod(filename, S_IREAD); 
   if (stat) 
      printf("Couldn't make %s read-only\n", filename); 
   else 
      printf("Made %s read-only\n", filename); 
}
==========
==========
clearerr
函数cleaeerr()用来把stream指向的文件的出错标记重新设置为零。文件的结束指示器也被重新设置
程序例: 

#include <stdio.h> 

int main(void) 
{ 
   FILE *fp; 
   char ch; 

   /* open a file for writing */ 
   fp = fopen("DUMMY.FIL", "w"); 

   /* force an error condition by attempting to read */ 
   ch = fgetc(fp); 
   printf("%c\n",ch); 

   if (ferror(fp)) 
   { 
      /* display an error message */ 
      printf("Error reading from DUMMY.FIL\n"); 

      /* reset the error and EOF indicators */ 
      clearerr(fp); 
   } 

   fclose(fp); 
   return 0; 
}
==========
==========
close
说明:关闭与fd相关连的文件,如果调用成功返回0,不成功则返回-1。
程序例: 

#include <string.h> 
#include <stdio.h> 
#include <fcntl.h> 
#include <io.h> 

main() 
{ 
   int handle; 
   char buf[11] = "0123456789"; 

   /* create a file containing 10 bytes */ 
   handle = open("NEW.FIL", O_CREAT); 
   if (handle > -1) 
   { 
       write(handle, buf, strlen(buf)); 

       /* close the file */ 
       close(handle); 
   } 
   else 
   { 
       printf("Error opening file\n"); 
   } 
   return 0; 
}
==========
==========
cprintf
说明:该函数操作成功时,返回输出字数
程序例: 

#include <conio.h> 

int main(void) 
{ 
   /* clear the screen */ 
   clrscr(); 

   /* create a text window */ 
   window(10, 10, 80, 25); 

   /* output some text in the window */ 
   cprintf("Hello world\r\n"); 

   /* wait for a key */ 
   getch(); 
   return 0; 
}
==========
==========
creat
函数create()是UNIX型文件系统中的一员,它不是ANSI标准定义的,它生成一个名字由filename指定的新文件用于写操作,打开成功时creat()返回一个大于或等于0的文件句柄,失败是时返回-1
pmode决定文件访问模式的设置,pmode的值很大程度上取决于操作系统。使用宏S_IWRITE(只写)和S_IREAD(只读)来作为pmode的值。

在调用creat时,如所指定的文件已存在,该文件会被抹去,所有的原内容都丢失,除非该文件有写保存护。
程序例: 

#include <sys\stat.h> 
#include <string.h> 
#include <fcntl.h> 
#include <io.h> 

int main(void) 
{ 
   int handle; 
   char buf[11] = "0123456789"; 

   /* change the default file mode from text to binary */ 
   _fmode = O_BINARY; 

   /* create a binary file for reading and writing */ 
   handle = creat("DUMMY.FIL", S_IREAD | S_IWRITE); 

   /* write 10 bytes to the file */ 
   write(handle, buf, strlen(buf)); 

   /* close the file */ 
   close(handle); 
   return 0; 
}
==========
==========
_creat
与creat()作用一样,只是使用一个DOS的文件属性字节,attrib参数可以是下述宏之一:
FA_RDONLY 把文件设置为只读文件
FA_HIIDDEN 设置为隐含文件
FA_SYSTEM设置为系统文件
==========
==========
creatnew
函数createnew()与creat()一样,只是当文件已存在时,createnew()返回出错信息,并且不抹除原文件
程序例: 

#include <string.h> 
#include <stdio.h> 
#include <errno.h> 
#include <dos.h> 
#include <io.h> 

int main(void) 
{ 
   int handle; 
   char buf[11] = "0123456789"; 

   /* attempt to create a file that doesn't already exist */ 
   handle = creatnew("DUMMY.FIL", 0); 

   if (handle == -1) 
      printf("DUMMY.FIL already exists.\n"); 
   else 
   { 
      printf("DUMMY.FIL successfully created.\n"); 
      write(handle, buf, strlen(buf)); 
      close(handle); 
   } 
   return 0; 
}
==========
==========
creattemp
函数creattemp()用来生成一个独特的临时文件,当调用creattemp()时,filename指向由反斜杠结束的路径名,在返回时,filename包含一个独特的文件名,你必须保证filename有足够的长度来装该文件名。
在这些函数出现错误时,errno被设置为下述值之一:
ENOENT 路径或文件名不存在
EMFILE 打开文件太多
EACCES 拒绝文访问
程序例: 

#include <string.h> 
#include <stdio.h> 
#include <io.h> 

int main(void) 
{ 
   int handle; 
   char pathname[128]; 

   strcpy(pathname, "\\"); 

   /* create a unique file in the root directory */ 
   handle = creattemp(pathname, 0); 

   printf("%s was the unique file created.\n", pathname); 
   close(handle); 
   return 0; 
}
==========
==========
abort
==========
==========
abs
==========
==========
absread, abswirte
==========
==========
acos
==========
==========
allocmem
==========
==========
arc
==========
==========
asctime
==========
==========
asin
==========
==========
assert
==========
==========
atan
==========
==========
atan2
==========
==========
atexit
==========
==========
atof
==========
==========
atoi
==========
==========
atol
==========
==========
bar
==========
==========
bar3d
==========
==========
bdos
==========
==========
bdosptr
==========
==========
bioscom
==========
==========
biosdisk
==========
==========
biosequip
==========
==========
bioskey
==========
==========
biosmemory
==========
==========
biosprint
==========
==========
biostime
==========
==========
brk
==========
==========
bsearch
==========
==========
cabs
==========
==========
calloc
==========
==========
ceil
==========
==========
chdir
==========
==========
chsize
==========
==========
circle
==========
==========
cleardevice
==========
==========
clearviewport
==========
==========
clock
==========
==========
closegraph
==========
==========
clreol
==========
==========
clrscr
==========
==========
coreleft
==========
==========
cos
==========
==========
cosh
==========
==========
country
==========
==========
cputs
==========
==========
cscanf
==========
==========
ctime
==========
==========
ctrlbrk
==========
==========
cabs
==========
==========
calloc
==========
==========
ceil
==========
==========
cgets
==========
==========
chdir
==========
==========
_chmod, chmod
==========
==========
chsize
==========
==========
circle
==========
==========
cleardevice
==========
==========
clearerr
==========
==========
clearviewport
==========
==========
_close, close
==========
==========
clock
==========
==========
closegraph
==========
==========
clreol
==========
==========
clrscr
==========
==========
coreleft
==========
==========
cos
==========
==========
cosh
==========
==========
country
==========
==========
cprintf
==========
==========
cputs
==========
==========
_creat creat
==========
==========
creatnew
==========
==========
creattemp
==========
==========
cscanf
==========
==========
ctime
==========
==========
ctrlbrk
==========
==========
delay
==========
==========
delline
==========
==========
detectgraph
==========
==========
difftime
==========
==========
disable
==========
==========
div
==========
==========
doterr
==========
==========
dostounix
==========
==========
drawpoly
==========
==========
dup
==========
==========
dup2
==========
==========
delay
==========
==========
delline
==========
==========
detectgraph
==========
==========
difftime
==========
==========
disable
==========
==========
div
==========
==========
doterr
==========
==========
dostounix
==========
==========
drawpoly
==========
==========
dup
==========
==========
dup2
==========
==========
ecvt
==========
==========
ellipse
==========
==========
enable
==========
==========
eof
==========
==========
execl
==========
==========
exit
==========
==========
exp
==========
==========
ecvt
==========
==========
ellipse
==========
==========
enable
==========
==========
eof
==========
==========
exec...
==========
==========
exit
==========
==========
exp
==========
==========
gcvt
==========
==========
geninterrupt
==========
==========
getarccoords
==========
==========
getaspectratio
==========
==========
getbkcolor
==========
==========
getc
==========
==========
getcbrk
==========
==========
getch
==========
==========
getchar
==========
==========
getche
==========
==========
getcolor
==========
==========
getcurdir
==========
==========
getcwd
==========
==========
getdate
==========
==========
getdefaultpalette
==========
==========
getdisk
==========
==========
getdrivername
==========
==========
getdta
==========
==========
getenv
==========
==========
getfat, getfatd
==========
==========
getfillpattern
==========
==========
getfillsettings
==========
==========
getftime
==========
==========
getgraphmode
==========
==========
getftime
==========
==========
getgraphmode
==========
==========
getimage
==========
==========
getlinesettings
==========

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -