[C] 从远堆中分配存储块 →→→→→进入此内容的聊天室

来自 , 2019-12-29, 写在 C, 查看 126 次.
URL http://www.code666.cn/view/8ca8da41
  1. #include <stdio.h>
  2. #include <alloc.h>
  3. #include <string.h>
  4. #include <dos.h>
  5.  
  6. int main ( void )
  7. {
  8.         char far *fptr;
  9.         char *str = "Hello";
  10.  
  11.         /* allocate memory for the far pointer */
  12.         fptr = farmalloc ( 10 );
  13.  
  14.         /* copy "Hello" into allocated memory */
  15.         /*
  16.            Note: movedata is used because we might
  17.            be in a small data model, in which case
  18.            a normal string copy routine can not be
  19.            used since it assumes the pointer size
  20.            is near.
  21.         */
  22.         movedata ( FP_SEG ( str ), FP_OFF ( str ),
  23.                    FP_SEG ( fptr ), FP_OFF ( fptr ),
  24.                    strlen ( str ) );
  25.  
  26.         /* display string (note the F modifier) */
  27.         printf ( "Far string is: %Fs\n", fptr );
  28.  
  29.         /* free the memory */
  30.         farfree ( fptr );
  31.  
  32.         return 0;
  33. }
  34.  

回复 "从远堆中分配存储块"

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

captcha