Hey! I have a problem. I've been coding Python for two years now, and it's great, but now I'd like to use a module called "ctypes" to import C function into Python. I know how to do it and all, but the problem is: I know how to program in C# (a fair bit) but I have no clue of how to translate that into ordinary C. Here's my C# function (in case you know C#, of course):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KarlsTools;

public class Program
{
    public static Array ITERATE(double z_r,double z_i,double c_r,
                        double c_i, int iterations, 
                        double limit)
    {
        Complex z = new Complex(z_r, z_i);
        Complex c = new Complex(c_r, c_i);

        for (double i = 1; Math.Round(i) <= iterations; i++)
        {
            z = Complex.Pow(z, 2) + c;
            if (Complex.Abs(z) < limit)
            {
                double[] numbers = new double[] { Complex.Real(z),
                                                  Complex.Imag(z),
                                                  Complex.Real(c),
                                                  Complex.Imag(c),
                                                  i};
                return numbers;
            }
        }
        double iter = iterations;
        double[] result = new double[]        { Complex.Real(z),
                                                  Complex.Imag(z),
                                                  Complex.Real(c),
                                                  Complex.Imag(c),
                                                  iter};
        return result;
    }
}

Could anyone provide some directives on how to translate this little piece of code into C? I mean, it's a REALLY simple function so it must take like 5 minutes to write it in C, just that I don't know how. I woldn't even have to import a complex math module since C has native support for complex math... Thank you in advance.

"Translating" into languages isn't the easiest of tasks, especially C# into C. C# is .net based on OOD whereas C is a functional language.. Even C++ isn't true OOD. I'd suggest reading up on how to create C++ classes and translate this code into C++.

I know that true OOD is just in C#, but I don't want any OOD at all. I just want a really simple function that takes six args (type double) and returns an array of five (also type double)... Than can be done on any of the tree, I just don't know how to put it correctly on C

Don't forget to mention where else you posted, so that we don't waste OUR time saying what has already been said.

You might be considerate to post a link back here on the SO site.

If that is all it is doing

double* foo(couble d1,double d2,double d3,double d4,double d5,double d6)
{
    double* d = malloc(5 * sizeof(double));
    d[0] = d1;
    d[1] = d2;
    // etc

    return d;

}

@Salem: Sorry mate, didn't think about that, I will keep it mind for the next time.
@Ancient Dragon: Thanks that helped me out a bit, now I'm translating the function myself (not that hard, as I said, it is fairly simple)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.