1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include <stdio.h>
#include <math.h>
void write_at(int pos);
int read_at(int pos);
int main ()
{
char c;
int f, pos, n;
FILE * pFile;
pFile = fopen("C:/a/exp.txt" , "w");
for (f = 1; f<40001; f++) {
fprintf(pFile, "0");
if (!(f%200) && f<40000) {
fprintf(pFile, "%c", '\n');
}
}
fflush(pFile);
fclose (pFile);
for( n = 0; n<40000; n++) {
read_at(n);
}
return 0;
}
void write_at(int pos)
{
FILE * pFile;
pFile = fopen("C:/a/exp.txt" , "r+b");
fseek (pFile , pos , SEEK_SET);
fputs ( "1" , pFile );
fflush(pFile);
fclose ( pFile );
}
int read_at(int pos)
{
FILE * pFile;
int c;
pFile = fopen("C:/a/exp.txt" , "r+b");
fseek (pFile , pos , SEEK_SET);
while ((c = fgetc(pFile)) != EOF) {
printf("pos=%d \t %c\n", pos, c);
return pos;
}
fflush(pFile);
fclose ( pFile );
return 0;
}
|