help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

string help


From: John W. Eaton
Subject: string help
Date: Wed, 3 Jun 1998 09:50:23 -0500 (CDT)

On  3-Jun-1998, Karen L. Kalat <address@hidden> wrote:

| I'm having trouble turning a character array in C++ into
| a returnable Octave value.  If I have a variable, say 
| char[100] in my C function, how do I translate it to an octave type?
| Also , how would I return an Array or Matrix of strings?

Here's a simple example:

  #include <octave/oct.h>

  DEFUN_DLD (foo, , ,
    "")
  {
    octave_value_list retval;

    string_vector sv(5);

    sv[0] = "this";
    sv[1] = "is";
    sv[2] = "a";
    sv[3] = "string";
    sv[4] = "vector";

    retval(1) = sv;

    char buf[100];

    strcpy (buf, "hello, world!");

    retval(0) = buf;

    return retval;
  }

It produces to output values.  The first is a string, and the second
is an array of strings:

  octave:1> [x,y] = foo
  x = hello, world!

  y =

  this
  is
  a
  string
  vector

jwe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]