Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C- function return a vector

Name: Anonymous 2006-11-27 9:46

Good afternoon /prog/, its me again
i need to make a C funcion that returns a vector

so... how do i made C funcion return vector?

Name: Anonymous 2006-11-27 10:00

well, first, you have to make a struct called 'vector'.  then have your C function return it.

alternatively, use C++, which actually /has/ vectors.

Name: Anonymous 2006-11-27 10:09

i cant use c++ cuz its my c class
thanks

Name: Anonymous 2006-11-27 10:16

use return;

Name: Anonymous 2006-11-27 10:19

oh, by the way, could you give me some code example please?

Name: Anonymous 2006-11-27 11:03

>>1
There are no vectors in C, but you can return a pointer to the first element of something. For example, an array of wchar_t:

wchar_t *CreateArray() {
    //Create an array of, say 10 wchar_t
    wchar_t *myarray = malloc(10 * sizeof(wchar_t));
    //Return it
    return myarray;  
}

void ObtainArray() {
    wchar_t *myarray; //We'll store the result here
    //Call CreateArray to create the array
    myarray = CreateArray();
}



Of course, this assumes you know the length of the array. If the function CreateArray doesn't know the length but ObtainArray does, you can make ObtainArray pass the length to CreateArray as an argument. If the length can be arbitrary and cannot be known beforehand, you'll have to mark it somehow. It's common for char and wchar_t strings to mark the end with a zero. For other stuff, you can define a struct like:

struct stuff {
    int len; //Length
    something *ptr; //Pointer to beginning
}

Name: Anonymous 2006-11-27 11:34

Avoiding the basics isn't going to help you learn.

In fact it'll make you a horrible programmer.

Name: Anonymous 2006-11-27 12:24

Do you mean a C++ style vector, or a mathematical type of vector?

Name: Anonymous 2006-11-28 22:57

return (Vector)your_variable;

Name: Anonymous 2008-02-07 17:03

C-function

VALID EMACS CODE

Name: Anonymous 2010-12-08 21:51

Name: Anonymous 2010-12-09 9:03

Name: Anonymous 2010-12-10 16:20

Name: Sgt.Kabu⪲ూkiman禜쒶 2012-05-28 21:13

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List