标签:文件 随机 fseek
#include<stdio.h> #include<stdlib.h> void main() { FILE *fpIn,*fpOut; fpOut = fopen("shuzu.txt","wb"); //以二进制只写方式 if(NULL == fpOut) { printf("Error:Open file fail !\n"); exit(1); } int a[10] = {1,22,333,4444,55555,666666,7777777,88888888,999999999,1000000000}; fwrite(a,sizeof(int),10,fpOut); fpIn = fopen("shuzu.txt","rb"); //以二进制只读方式 if(NULL == fpIn) { printf("Error:Open file fail !\n"); exit(1); } while(1) { int i; int j; printf("请输入第i个数:\n"); scanf("%d",&i); fseek(fpIn,(i-1)*sizeof(int),SEEK_SET); fread(&j,sizeof(int),1,fpIn); printf("第 %d 个数为:%d\n",i,j); } fclose(fpOut); fclose(fpIn); }
本文出自 “10747227” 博客,转载请与作者联系!
标签:文件 随机 fseek
原文地址:http://10757227.blog.51cto.com/10747227/1707923