欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當前位置:主頁 > 軟件編程 > C語言 >

C語言實現(xiàn)txt數(shù)據(jù)讀入內(nèi)存/CPU緩存實例詳解

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊: 次

摘要

C實現(xiàn)將txt數(shù)據(jù)讀入內(nèi)存/CPU緩存的函數(shù),不多說,實現(xiàn)如下。

1. 實現(xiàn)代碼

#include "stdafx.h" 
#include <stdio.h> 
#include <stdlib.h> 
 
int filelength(FILE *fp); 
char *readfile(char *path); 
 
 
int main(void){ 
  char *string; 
 
  string=readfile("C:/Users/Joe WANG/Desktop/Data.txt"); 
  printf("數(shù)據(jù)讀入內(nèi)存完畢! \n"); 
  printf("內(nèi)存中的數(shù)據(jù)如下:\n%s \n",string); 
  system("pause"); 
   
  return 0; 
} 
 
char *readfile(char *path){ 
  FILE *fp;   
  int length; 
  char *ch; 
   
  if((fp=fopen(path,"r"))==NULL){ 
    printf("open file %s error.\n",path); 
    exit(0); 
  } 
  length=filelength(fp); 
  ch=(char *)malloc(length); 
  fread(ch,length,1,fp); 
  *(ch+length)='\0'; 
   
  return ch; 
} 
 
int filelength(FILE *fp){ 
  int num; 
   
  fseek(fp,0,SEEK_END); 
  num=ftell(fp); 
  fseek(fp,0,SEEK_SET); 
   
  return num; 
} 

2. Data.txt中的源數(shù)據(jù)

3. 測試結(jié)果

網(wǎng)頁制作CMS教程網(wǎng)絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有