C 언어 구현 txt 데이터 읽 기 메모리/CPU 캐 시 인 스 턴 스 상세 설명
C.txt 데 이 터 를 메모리/CPU 캐 시 에 읽 는 함 수 를 실현 합 니 다.더 이상 말 하지 않 고 다음 과 같 습 니 다.
1.구현 코드
#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(" !
");
printf(" :
%s
",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.
",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 의 원본 데이터3.테스트 결과
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C 언어 구현 천둥 제거 게임 상세 정보먼저 작은 메뉴를 표시하고 게임을 할지 여부를 선택하십시오.사용자가 종료를 선택하면 프로그램 실행이 끝나고, 사용자가 게임을 선택하면 지뢰 제거 위치 좌표를 입력하라는 메시지가 표시됩니다.사용자가 입력한 좌표가 바둑...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.