home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_200
/
293_01
/
t2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-08-25
|
1KB
|
56 lines
/*
* Using FSEEK to position in a newly created file.
* Writing forwards and backwards.
*
*/
#include <stdio.h>
main()
{
FILE *fp;
char c[32];
int i, j;
long int l;
/* forwards */
if ((fp = fopen("t2f.tmp", "wb")) == NULL) {
printf("Error creating file\n");
exit(1);
}
for (i = 0; i < 32; i++) {
l = (long) i * 32;
if (fseek(fp, l, SEEK_SET)) {
printf("Error seeking\n");
exit(1);
}
for (j = 0; j < 32; j++)
c[j] = i;
if (fwrite(c, sizeof(char), 32, fp) != 32*sizeof(char)) {
printf("Error writing\n");
exit(1);
}
}
/* backwards */
if ((fp = freopen("t2b.tmp", "wb", fp)) == NULL) {
printf("Error creating file\n");
exit(1);
}
for (i = 31; i >= 0; i--) {
l = (long) i * 32;
if (fseek(fp, l, SEEK_SET)) {
printf("Error seeking\n");
exit(1);
}
for (j = 0; j < 32; j++)
c[j] = i;
if (fwrite(c, sizeof(char), 32, fp) != 32*sizeof(char)) {
printf("Error writing\n");
exit(1);
}
}
}