Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

[ÖØÒª]CÖÐfread()º¯ÊýµÄ·µ»ØÖµ

 ×î½üÓиöÏîÄ¿ÐèÒªÔÚUNIXÏÂÓÃC×ö£¬ºÜ¾ÃûÓùýCÁË£¬·¢ÏÖЩÎÊÌâÈÝÒ׸ã´í¡£
      
    Õâ¸öÎÊÌâºÜÈÝÒ׸ã´í£¬²¢µ¼ÖºܶàÎÊÌ⣬ÐèҪǿµ÷µÄÊÇfreadº¯Êý·µ»ØµÄ²¢²»ÊÇ×Ö½ÚÊý¡£
realRead = fread(buf,item,count,fp)    £¨Ã¿´Î¶Áitem´óСµÄÊý¾Ý¿é£¬·Öcount´ÎÀ´¶Á¡££©
¶øÊÇ·µ»ØµÄÊdzɹ¦ÓÐЧµÄ¶ÁÈ¡µÄitemÔªËصĸöÊý£¬¶ø³É¹¦¶ÁÈëµÄ×Ö½ÚÊýÔòÊÇrealRead * sizeof(item)
Ò»°ã˵À´realRead ÊÇСÓÚcountµÄ£¬ºÜÇɵÄÇé¿ö¾Í¸ÕºÃΪcount.³ý·ÇÎļþ´óС¸ÕºÃΪitem´óСµÄÕûÊý±¶¡£
·µ»ØµÄÊÇÕæʵ¶ÁÈëitemÔªËصĸöÊý£¬ËäÈ»¶ÁÁËcount´Î£¬µ«ÊÇÕæÕý¶Áµ½µÄÓÐЧ¸öÊýΪrealRead¸ö
Õæʵ¶ÁÈë×Ö½ÚÊý¾ÍΪrealRead*sizeof(item)  
 RETURN VALUE
       fread  and  fwrite  return the number of items successfully read or written (i.e., not the number of
       characters).  If an error occurs, or the end-of-file is reached, the return value is  a  short  item
       count (or zero).
       fread does not distinguish between end-of-file and error, and callers must use feof(3) and ferror(3)
       to determine which occurred.
fread£¨´ÓÎļþÁ÷¶ÁÈ¡Êý¾Ý£©  
 
±íÍ·Îļþ  #include<stdio.h>
 
¶¨Ò庯Êý  size_t fread(void * ptr,size_t size,size_t count,FILE * stream);
 
º¯Êý˵Ã÷  fread()ÓÃÀ´´ÓÎļþÁ÷ÖжÁÈ¡Êý¾Ý¡£²ÎÊýstreamΪÒÑ´ò¿ªµÄÎļþÖ¸Õ룬²ÎÊýptr Ö¸ÏòÓû´æ·Å¶ÁÈ¡½øÀ´µÄÊý¾Ý¿Õ¼ä£¬¶ÁÈ¡µÄ×Ö½ÚÊýÒÔ²ÎÊýsize*countÀ´¾ö¶¨¡£
Fread()»á·µ»Øʵ¼Ê¶ÁÈ¡µ½µÄcountÊýÄ¿£¬Èç¹û´ËÖµ±È²ÎÊýcountÀ´µÃС£¬Ôò´ú±í¿ÉÄܶÁµ½ÁËÎļþβÁË»òÕßÓдíÎó·¢Éú(Ç°Õß¼¸ÂÊ´ó)£¬Õâʱ±ØÐëÓÃfeof()»òferror()À´¾ö¶¨·¢ÉúʲôÇé¿ö¡£
 
·µ»ØÖµ  ·µ»Øʵ¼Ê¶ÁÈ¡µ½µÄcountÊýÄ¿¡£
fread·µ»ØµÄ²»ÊÇ×Ö½ÚÊý£¬
µ±ÇÒ½öµ±ÏÂÃæÕâôÓõÄʱºò£¬·µ»ØÖµ²ÅÊÇ×Ö½ÚÊý£¨µ±È»ÒòΪǡºÃÒ»¸öÊý¾Ý¿é´óСΪ1¸ö×Ö½Ú£¬Ï൱ÓÚrealRead*1£©
char buff[size];
FILE *fp;
...
realRead = fread(buff, 1, size, fp);
...
Èç¹ûÊÇ: fread(buff, size, 1, fp)
·


Ïà¹ØÎĵµ£º

Delphi Óë C/C++ Êý¾ÝÀàÐͶÔÕÕ±í

Delphi Óë C/C++ Êý¾ÝÀàÐͶÔÕÕ±í
DelphiÊý¾ÝÀàÐÍC/C++
ShorInt
8λÓзûºÅÕûÊý
char
Byte
8λÎÞ·ûºÅÕûÊý
BYTE,unsigned short
SmallInt
16λÓзûºÅÕûÊý
short
Word
16λÎÞ·ûºÅÕûÊý
unsigned short
Integer,LongInt
32λÓзûºÅÕûÊý
int,long
Cardinal,LongWord/DWORD
32λÎÞ·ûºÅÕûÊý
unsigned long
Int6 ......

LinuxÏ»ñµÃϵͳʱ¼äµÄCÓïÑÔµÄʵÏÖ·½·¨

 LinuxÏ»ñµÃϵͳʱ¼äµÄCÓïÑÔµÄʵÏÖ·½·¨
#include<time.h>  //CÓïÑÔµÄÍ·Îļþ
#include<stdio.h>  //CÓïÑÔµÄI/O
void main()
{
time_t now;    //ʵÀý»¯time_t½á¹¹
struct tm  *timenow;    //ʵÀý»¯tm½á¹¹Ö¸Õë
time(&now);
//timeº¯Êý¶ÁÈ¡ÏÖÔÚµ ......

dz̸CÄÚ´æ·ÖÅä1

¹ØÓÚCÓïÑÔÄÚ´æ·½ÃæµÄ»°ÌâÒªÕæ˵ÆðÀ´µÄ»°ÄÇ¿ÖžÍûͷÁË£¬ËùÒÔ±¾ÎĽö½öÊÇÒ»¸ödz̸¡£
¹ØÓÚÄÚ´æÎÊÌâ
²»Í¬Æ½Ì¨Ö®¼äÓÐÒ»¶¨µÄÇø±ð¡£±¾ÎÄËùÖ¸µÄƽ̨ÊÇx86µÄLinux
ƽ̨
ÓÃCÓïÑÔ×ö³ÌÐò£¨ÆäʵÆäËûÓïÑÔÒ²Ò»Ñù£©£¬²»½öÒªÊìϤÓï·¨£¬ÆäʵºÜ¶àÏà¹ØµÄ±³¾°ÖªÊ¶Ò²ºÜÖØÒª¡£ÔÚѧϰºÍÑо¿CÓïÑÔÖÐÄÚ´æ·ÖÅäµÄÎÊÌâÇ°£¬Ê×ÏÈÒªÁ˽âÒ»ÏÂLinux·ÖÅä¸ø ......

Windows via C/C++£ºÏ̵߳ÄÖ´ÐÐʱ¼ä

¼ÆËãÏß³ÌÖ´ÐÐijÏîÈÎÎñÏûºÄµÄʱ¼äʱ£¬Ðí¶à¿ª·¢ÈËÔ±»áµ÷ÓÃGetTickCount/GetTickCount64±àдÈçϵĴúÂ룺
// Get the current time (start time)
ULONGLONG qwStartTime = GetTickCount64();
// Perform complex algorithm here
// Subtract start time from current time to get duration
ULONGLONG dwElapsedTime = Get ......

´ÓCµ½JAVA£¬¿ªÊ¼ÎÒµÄIT²ËÄñ֮·£¡

ÕæÕý·¢ÏÖÈËÉúÐèҪ֪ʶµÄʱºò£¬ÎÒµÄÇà´ºÒѾ­ÀË·ÑÁËÒ»°ë¡£
ÓÚÊǹÄÆðÓÂÆøÀ´µ½±±´óÇàÄñѧϰIT£¬¼øÓڶ෽¿¼ÂÇ£¬»¹ÊÇÑ¡ÔñÁËÈí¼þ²âÊÔ¡£
Èç½ñ¿ÎÒµµÄÒ»´ó°ëÒ²ÒѽáÊø£¬´Ó¸Õ¿ªÊ¼µÄÒ»ÎÞËùÖª£¬½¥½¥³É³¤ÎªÒ»¸ö²ËÄñ……
Ôڿγ̵Äѧϰ¹ý³ÌÖУ¬²Å½¥½¥·¢ÏÖ×Ô¼º¶ÔÓÚÕâ¸öÐÐÒµµÄÐËȤ£¬ÓÈÆäÊÇÈí¼þ¿ª·¢ÕâÒ»¿é¡£
ÉõÖÁ¶Ô×Ô¼ºÑ¡Ôñ×ö²â ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ