home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / editors / hypsh40b.arj / HYPDEVEL.LZH / CHILD.C < prev    next >
C/C++ Source or Header  |  1991-04-24  |  1KB  |  79 lines

  1. /*
  2. CHILD.C
  3. Copyright (c) Text Technology 1990
  4.  
  5. Example program to be run from HyperShell
  6. to access variables whose addresses are
  7. passed in the command line
  8.  
  9. Requires Turbo-C
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <dos.h>
  14. #include <string.h>
  15.  
  16. /*
  17. Simple example displays received value, awaits
  18. input of new value, sets new value and exits
  19.  
  20. */
  21.  
  22. main(argc, argv)
  23. int    argc;
  24. char    **argv;
  25. {
  26.     char var[80];
  27.  
  28.     getvariable(argv[1],var);
  29.     printf("Received %s\nEnter string to return: ", var);
  30.     gets(var);
  31.     putvariable(argv[1],var);
  32.  
  33.     exit(0);
  34. }
  35.  
  36. /*
  37. GETVARIABLE
  38.  
  39. gets contents of variable whose address is in addstr
  40. and places it in tostr (this needs to be pre-allocated)
  41. */
  42.  
  43. getvariable(addstr,tostr)
  44. char    *addstr;
  45. char    *tostr;
  46. {
  47.     char far *variable;
  48.  
  49.     sscanf(addstr,"%Fp", (void far *)&variable);
  50.     sprintf(tostr, "%Fs", (char far *)variable);
  51.  
  52.     return(0);
  53. }
  54.  
  55. /*
  56. PUTVARIABLE
  57.  
  58. sets contents of variable whose address is in addstr
  59. to value from fromstr
  60. */
  61.  
  62. putvariable(addstr,fromstr)
  63. char    *addstr;
  64. char    *fromstr;
  65. {
  66.     char far *variable;
  67.  
  68.     sscanf(addstr,"%Fp", (void far *)&variable);
  69.     /* cannot use strcpy, have to do own copy */
  70.     while(*variable++ = *fromstr++)
  71.     /* null statement - work done in while */
  72.         ;
  73.  
  74.     return(0);
  75. }
  76.  
  77.  
  78. /* end of source program */
  79.