Laden...

Forenbeiträge von clamb Ingesamt 5 Beiträge

05.03.2014 - 08:12 Uhr

Alles klar. Besten Dank. Es funktioniert.

04.03.2014 - 15:26 Uhr

Ah ok, mit delegate.
Ich will diesen nach C# portieren, auf C Bibliotheken ist kein Zugriff notwendig.

Würde dann der vollständige Konstruktor für MENU_STATE so aussehen?


public delegate byte _pFunc(byte input);
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]

public struct MENU_STATE
{
    public byte state;
    public string pText;
    public _pFunc AnonymousMember1;

    public MENU_STATE(byte _state, string _pText, _pFunc _AnonymousMember1)
    {
          state = _state;
          pText = _pText;
          AnonymousMember1 = _AnonymousMember1;
     }
}

04.03.2014 - 14:46 Uhr

Windows XP verweigert mir leider die Installation, da es sich angeblich um eine schädliche Software handelt. Gibt es alternativen?

04.03.2014 - 13:32 Uhr

Hallo,

ich beschäftige mich zur Zeit mit der Menüstruktur des AVR Butterfly und versuche diese von C in C# umzustricken. Da meine Erfahrungen in C# sehr gering sind, bin ich auch direkt auf ein Problem gestossen.

Zunächst einmal hier ein Ausschnitt des alten Codes:


#define ST_AVRBF                = 10;
#define ST_AVRBF_REV         = 11;
char MT_AVRBF[]                     = "AVR Butterfly";
.....

typedef struct
{
    unsigned char state;
    unsigned char input;
    unsigned char nextstate;
} MENU_NEXTSTATE;


typedef struct
{
    unsigned char state;
    char  *pText;
    char (*pFunc)(char input);
} MENU_STATE;

MENU_NEXTSTATE menu_nextstate[] = {
//   STATE                         INPUT          NEXT STATE
    {ST_AVRBF,                  KEY_PLUS,   ST_OPTIONS},
    {ST_AVRBF,                  KEY_NEXT,    ST_AVRBF_REV}
};

MENU_STATE menu_state[] = {
//  STATE                               STATE TEXT              STATE_FUNC
    {ST_AVRBF,                       MT_AVRBF,                NULL},
    {ST_AVRBF_REV,                NULL,                       Revision}
};

Und hier mein erster Versuch den Code in C# umzuschreiben.


public const int ST_AVRBF                = 10;
public const int ST_AVRBF_REV         = 11;
char[] MT_AVRBF                     = {'A','V','R',' ','B','u','t','t','e','r','f','l','y'};
....

public struct MENU_NEXTSTATE
        {
            int state;
            int input;
            int nextstate;

            public MENU_NEXTSTATE(int _state, int _input, int _nextstate)
            {
                state       = _state;
                input       = _input;
                nextstate   = _nextstate;
            }
        }


        unsafe public struct MENU_STATE
        {
            int state;
            char* pText;
            char *pFunc(char input);
        }

MENU_NEXTSTATE[] menu_nextstate = {
//                                   STATE                      INPUT                   NEXT STATE
   new MENU_NEXTSTATE(ST_AVRBF,                KEY_PLUS,            ST_OPTIONS),
   new MENU_NEXTSTATE(ST_AVRBF,                KEY_NEXT,            ST_AVRBF_REV)
};

MENU_STATE[] menu_state = {
                        // STATE                              STATE TEXT               STATE_FUNC
   new MENU_STATE(ST_AVRBF,                      MT_AVRBF,                NULL),
   new MENU_STATE(ST_AVRBF_REV,               NULL,                       Revision)
};

Mein Frage ist: Wie muss der Konstruktor des Structs MENU_STATE aussehen, wenn dieser Zeigervariablen und Zeiger auf Funktionen beinhaltet?
Und gibt es sonst noch Verbesserungsvorschläge?

Gruß
C

26.07.2012 - 18:13 Uhr

Hallo zusammen,

bin neu hier und habe folgendes Problem:

Ich habe 2 Zwei-Dimensionale Array erstellt, die ich mit Zufallszahlen füllen möchte.
Soweit, so gut. Meine Funktion füllt beide Arrays und gibt sie mir auch in der Console richtig aus. Allerdings füllt meine Funktion beide Arrays mit den gleichen Zufallszahlen.

Hier einmal der Code:


        static void ausgabeArray(double[,] arr, int z, int s)
        { 
            for(int i = 0; i < z; i++)
            {
                for (int j = 0; j < s; j++)
                    Console.Write("\t{0}", arr[i, j]);

                Console.WriteLine();
            }
        }

        static double[,] arrayFuellen(double[,] arr, int z, int s)
        {
            Random rnd = new Random();
            
            for (int i = 0; i < z; i++)
                for (int j = 0; j < s; j++)
                    arr[i, j] = rnd.Next(-30, 40);
            return arr;
        }

        static void Main(string[] args)
        {
            int z = 0, s = 0;

            Console.Write("Anzahl der Zeilen: ");
            z = Convert.ToInt32(Console.ReadLine());
            Console.Write("Anzahl der Spalten: ");
            s = Convert.ToInt32(Console.ReadLine());

            double[,] l = new double[z, s];
            double[,] m = new double[z, s];
            
            l = arrayFuellen(l, z, s);
            m = arrayFuellen(m, z, s);

            ausgabeArray(l, z, s);
            Console.WriteLine("\n + \n");
            ausgabeArray(m, z, s);

            Console.ReadLine();
        }

Komme nicht wirklich vorran. Kann mir jemand helfen bzw. erklären warum das so ist?

Gruß
clamb