Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

malloc(3C)

strdup(3C)



strsave(3C)                    DG/UX 5.4R3.00                    strsave(3C)


NAME
       strsave, strnsave - allocate area large enough to hold string and
       move string into it

SYNOPSIS
       char *string, *newstring, *strsave(const char *);
       ...
       newstring = strsave(string);

       char *string, *newstring, *strnsave(const char *, int);
       int n;
       ...
       newstring = strnsave(string, n);

       string    A byte pointer to a character string.
       newstring A byte pointer to the area allocated to receive a copy of
                 the string.
       n         The maximum number of characters to copy.

DESCRIPTION
       The strsave function allocates with malloc an area large enough to
       hold a specified string and moves a copy of the string into the area.
       It then returns a pointer to the area.

       The strsave and strnsave functions are the same except that with
       strnsave you specify a maximum number of bytes to copy.  The include
       files string.h and strings.h define these functions.

   Return Value
       Each function returns a pointer to the allocated area.  Each returns
       a null if it cannot allocate the area.

EXAMPLES
       /* Program test1 for the strsave() function */

       #include <string.h>
       #include <stdio.h>
       char *newloc, *strsave(const char *);
       int i = 1;
       main(argc, argv)
       int argc;
       char *argv[];
       {
           while (i < argc) {
               newloc = strsave(argv[i]);
               printf("\tStored argv[%d] at %o.\n", i, newloc);
               printf("argv[%d] = `%s'\n", i, newloc);
               i++;
           }
           return 0;
       }

       A call to the program test1 with the arguments




Licensed material--property of copyright holder(s)                         1




strsave(3C)                    DG/UX 5.4R3.00                    strsave(3C)


       Save these strings.

       generates the output

                Stored argv[1] at 34003540370.
       argv[1] = `Save'
                Stored argv[2] at 34003540410.
       argv[2] = `these'
                Stored argv[3] at 34003540430.
       argv[3] = `strings.'

       The locations vary with execution.

       /* Program test2 for the strnsave() function */

       #include <string.h>
       #include <stdio.h>
       #define MAX     80
       char *newloc, *strnsave(const char *, int);
       int i = 1;
       main(argc, argv)
       int argc;
       char *argv[];
       {
           while (i < argc) {
               newloc = strnsave(argv[i], MAX);
               printf("Stored argv[%d] at %o.0, i, newloc);
               printf("argv[%d] = `%s'0, i, newloc);
               i++;
           }
           return 0;
       }

       A call to the program test2 with the arguments

       Find some addresses.

       generates the output

                Stored argv[1] at 34003703644.
       argv[1] = `Find'
                Stored argv[2] at 34003677500.
       argv[2] = `some'
                Stored argv[3] at 34003677344.
       argv[3] = `addresses.'

       The locations vary with execution.

SEE ALSO
       malloc(3C), strdup(3C).







Licensed material--property of copyright holder(s)                         2


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026