diff sbr/add.c @ 0:bce86c4163a3

Initial revision
author kono
date Mon, 18 Apr 2005 23:46:02 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sbr/add.c	Mon Apr 18 23:46:02 2005 +0900
@@ -0,0 +1,24 @@
+/* add.c - concatenate two strings in managed memory */
+
+#include "../h/mh.h"
+#include <stdio.h>
+
+
+char   *add (this, that)
+register char  *this,
+               *that;
+{
+    register char  *cp;
+
+    if (!this)
+	this = "";
+    if (!that)
+	that = "";
+    if ((cp = malloc ((unsigned) (strlen (this) + strlen (that) + 1))) == NULL)
+	adios (NULLCP, "unable to allocate string storage");
+
+    (void) sprintf (cp, "%s%s", that, this);
+    if (*that)
+	free (that);
+    return cp;
+}