CÓïÑÔ±ê×¼IOÎļþ²Ù×÷
fopen
Í·Îļþ£º#include <stdio.h>
º¯ÊýÔÐÍ£ºFILE *fopen(const char *path, constchar *mode);
º¯Êý¹¦ÄÜ£º´ò¿ªÒ»¸öÎļþpath£¬»ñÈ¡µ½´ËÎļþµÄÎļþÁ÷Ö¸Õë
ÎļþÁ÷Ö¸Õ룺FILE*
typedef struct file_buf{
int fd;
char buf[size];
} FILE ;
ÐβÎÁÐ±í£º
path£ºÒª´ò¿ªÎļþÁ÷Ö¸ÕëµÄÎļþ
mode£º²Ù×÷·½Ê½
r £ºÖ»¶Á£¨²»ÄÜ´´½¨Îļþ£©
r+ £º¶Áд£¨¸²¸Çд£¬²»ÄÜ´´½¨Îļþ£©
w £ºÖ»Ð´£¨Çå¿Õд£¬¿ÉÒÔ´´½¨Îļþ£©
w+ £º¶Áд£¨Çå¿Õд£¬¿ÉÒÔ´´½¨Îļþ£©
a £ºÖ»Ð´£¨×·¼Óд£¬¿ÉÒÔ´´½¨Îļþ£©
a+ £º¶Áд£¨×·¼Óд£¬¿ÉÒÔ´´½¨Îļþ£©
·µ»ØÖµ£º
³É¹¦£ºÎļþÁ÷Ö¸Õë
ʧ°Ü£ºNULL
д´½¨µÄÎļþ£¬È¨ÏÞĬÈÏΪ0666
fclose
º¯ÊýÔÐÍ£ºint fclose(FILE*fp);
º¯Êý¹¦ÄÜ£º¹Ø±ÕfpÎļþÁ÷Ö¸Õë
ÐβÎÁÐ±í£º
fp£ºÒª¹Ø±ÕµÄÎļþÁ÷Ö¸Õë
·µ»ØÖµ£º
³É¹¦£º0
ʧ°Ü£ºEOF
fread
º¯ÊýÔÐÍ£ºsize_tfread(void *ptr, size_t size, size_t nmemb, FILE *stream);
º¯Êý¹¦ÄÜ£º´ÓstreamÎļþÁ÷Ö¸ÕëÖ¸ÏòµÄÎļþÖУ¬¶ÁÈ¡size*nmemb¸ö×Ö½ÚÊý¾Ý£¬´æ´¢µ½ptrÖ¸ÏòµÄ»º´æÇøÖÐ
ÐβÎÁÐ±í£º
ptr£º´æ´¢Êý¾ÝµÄ»º´æÇø
size£ºÒ»¿éÊý¾ÝµÄ×Ö½Ú´óС
nmemb£º¿éÊý£¬ÓжàÉÙ¿ésize´óСµÄÊý¾Ý
stream£ºÐèÒª¶ÁÈ¡Êý¾ÝµÄÎļþÁ÷Ö¸Õ루Êý¾ÝÀ´Ô´£©
·µ»ØÖµ£º
³É¹¦£º¶ÁÈ¡µ½µÄ¿éÊý£¬²»¹»Ò»¿éµÄ²»ËãÒ»¿é
ʧ°Ü/Îļþĩβ£º0
ÀýÈ磺fread(buf,100, 5, fp);
freadº¯Êý£¬¿ÉÒÔ¶ÁÈ¡µ½»Ø³µ£¬²»»áÒòΪ»Ø³µ¶øÍ£Ö¹¶ÁÈ¡£¬Ò²²»»áÒòΪ¿Õ¸ñ¶øÍ£Ö¹¶ÁÈ¡
fwrite
º¯ÊýÔÐÍ£ºsize_tfwrite(const void *ptr, size_t size, size_t nmemb,FILE *stream);
º¯Êý¹¦ÄÜ£ºÍùstreamÎļþÁ÷Ö¸ÕëÖ¸ÏòµÄÎļþÖУ¬Ð´Èësize*nmemb¸ö×Ö½ÚµÄÊý¾Ý£¬Êý¾ÝÀ´Ô´ÊÇptrÖ¸ÕëÖ¸ÏòµÄ»º´æÇø
ÐβÎÁÐ±í£º
ptr£ºÖ¸ÏòҪдÈëµÄÊý¾ÝÀ´Ô´µÄÖ¸Õë
size£ºÒ»¿éÊý¾ÝµÄ×Ö½Ú´óС
nmemb£º¿éÊý£¬ÓжàÉÙ¿ésize´óСµÄÊý¾Ý
stream£ºÖ¸Ïò¶ÔÏóÎļþµÄÎļþÁ÷Ö¸Õë
·µ»ØÖµ£º
³É¹¦£ºÐ´ÈëµÄ¿éÊý
ʧ°Ü£º0
ÀýÈ磺fwrite(buf,100, 5, fp);
fwiteº¯Êý´ÓptrÖ¸ÏòµÄ»º´æÇøÖлñÈ¡Êý¾ÝдÈëµ½streamÖУ¬Óöµ½»Ø³µ»òÕß¿Õ¸ñ£¬²»»áÍ£Ö¹´ÓptrÖлñÈ¡Êý¾Ý£¬ÐβÎÒªÇó»ñÈ¡¶àÉÙ¸ö×Ö½Ú£¬¾Í»ñÈ¡¶àÉÙ¸ö×Ö½Ú£¬Èç¹ûptrÖ¸ÏòµÄ»º´æÇøÖÐÊý¾Ý²»¹»£¬fwite»á´ÓptrºóÔ½½çÍùÏ»ñÈ¡Êý¾Ý£¬Ð´Èëµ½streamÖÐ