[C] 随机块读 →→→→→进入此内容的聊天室

来自 , 2020-01-05, 写在 C, 查看 128 次.
URL http://www.code666.cn/view/95f8d990
  1. #include <process.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <dos.h>
  5.  
  6. int main(void)
  7. {
  8.    char far *save_dta;
  9.    char line[80], buffer[256];
  10.    struct fcb blk;
  11.    int i, result;
  12.  
  13.    /* get user input file name for dta */
  14.    printf("Enter drive and file name (no path - i.e. a:file.dat)\n");
  15.    gets(line);
  16.  
  17.    /* put file name in fcb */
  18.    if (!parsfnm(line, &blk, 1))
  19.    {
  20.       printf("Error in call to parsfnm\n");
  21.       exit(1);
  22.    }
  23.    printf("Drive #%d  File: %s\n\n", blk.fcb_drive, blk.fcb_name);
  24.  
  25.    /* open file with DOS FCB open file */
  26.    bdosptr(0x0F, &blk, 0);
  27.  
  28.    /* save old dta, and set new one */
  29.    save_dta = getdta();
  30.    setdta(buffer);
  31.  
  32.    /* set up info for the new dta */
  33.    blk.fcb_recsize = 128;
  34.    blk.fcb_random = 0L;
  35.    result = randbrd(&blk, 1);
  36.  
  37.    /* check results from randbrd */
  38.    if (!result)
  39.       printf("Read OK\n\n");
  40.    else
  41.    {
  42.       perror("Error during read");
  43.       exit(1);
  44.    }
  45.  
  46.    /* read in data from the new dta */
  47.    printf("The first 128 characters are:\n");
  48.    for (i=0; i<128; i++)
  49.       putchar(buffer[i]);
  50.  
  51.    /* restore previous dta */
  52.    setdta(save_dta);
  53.  
  54.    return 0;
  55. }

回复 "随机块读"

这儿你可以回复上面这条便签

captcha