當前位置:編程學習大全網 - 網站源碼 - 謝謝啦,寫出fopen(),fread()函數參數以及返回值的數據類型及含義?

謝謝啦,寫出fopen(),fread()函數參數以及返回值的數據類型及含義?

FILE * fopen ( const char * filename, const char * mode );

size_t fread ( void * ptr, size_t size, size_t count, FILE * stream );

//fopen返回值是文件指針

//fread 返回值是讀到的元素個數

//size_t size,要讀取的每個元素的字節大小

// size_t count 元素個數

/* fread example: read a complete file */

#include <stdio.h>

#include <stdlib.h>

int main () {

FILE * pFile;

long lSize;

char * buffer;

size_t result;

pFile = fopen ( "myfile.bin" , "rb" );

if (pFile==NULL) {fputs ("File error",stderr); exit (1);}

// allocate memory to contain the whole file:

buffer = (char*) malloc (sizeof(char)*lSize);

if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}

// copy the file into the buffer:

result = fread (buffer,1,lSize,pFile);

if (result != lSize) {fputs ("Reading error",stderr); exit (3);}

/* the whole file is now loaded in the memory buffer. */

// terminate

fclose (pFile);

free (buffer);

return 0;

}

  • 上一篇:為什麽我玩CF穿越火線?菜單欄還在。幫幫我!
  • 下一篇:補碼源代碼移位
  • copyright 2024編程學習大全網