Autor Thema: mehrdimensionale Array  (Gelesen 5832 mal)

0 Mitglieder und 1 Gast betrachten dieses Thema.

Offline tuxie

  • Benutzer
  • Beiträge: 6.830
  • Falcon! Milan! Schuetzt die Raubvoegel!
mehrdimensionale Array
« am: Fr 15.08.2008, 22:18:01 »
Hallo,

ich arbeite an einem Projekt für den 8bitter dafür möchte ich einen AVR verwenden. Dieser wird in C Programmiert

Zum Darstellen eines Menüs auf einem Display, habe ich 2 Arrays angelegt die aber ausserhalb einer Funktion definiert und mit Daten gefüllt werden. Die Inhalte aber dann in einer Funktion weiter verwertet werden.

char* stry[4][6];
stry[1][1] = "Qme4.04";
stry[1][2] = "XL-OS";
stry[1][3] = "SPEEDER-OS";
stry[1][4] = "OLD-OS BIBOMON";
stry[1][5] = "OmniMon";
stry[1][6] = "OmniView";

stry[2][1] = "AUS";
stry[2][2] = "256KB RAMBO";
stry[2][3] = "256KB COMPYSHOP";
stry[2][4] = "512KB RAMBO";

stry[3][1] = "STANDART MONO";
stry[3][2] = "STEREO";

stry[4][1] = "KALTSTART";
stry[4][2] = "WARMSTART";

Jetzt soll das Array an eine Funktion übergeben werden.

wie stelle ich das am besten an.

TSchau Ingo
« Letzte Änderung: Fr 15.08.2008, 22:20:36 von tuxie »
Tschau Ingo

Offline AltF4

  • Benutzer
  • Beiträge: 49
Re: mehrdimensionale Array
« Antwort #1 am: Sa 16.08.2008, 02:29:42 »
Müsste eigentlich so funzen:

void empfaenger (const char ** stry)
{
   // mach was mit stry[i][j]
]

void aufrufer (void)
{
   empfaenger (stry);
}

Ich würde übrigens dringends empfehlen, die leerenArray-Einträge explizit auf NULL zu setzten, damit diese definierte Werte enthalten!

Gruß,
Ralph

Offline tuxie

  • Benutzer
  • Beiträge: 6.830
  • Falcon! Milan! Schuetzt die Raubvoegel!
Re: mehrdimensionale Array
« Antwort #2 am: Sa 16.08.2008, 10:18:48 »
Hallo,

ich danke dir. Jetzt muß ich nur schauen, der Compiler schmeißt mir jetzt jede menge Fehler um die Ohren wegen dem Array. Das ist wirklich blöd vor allem fällt mir nix anderes ein wie es mit einem Mehrdimenionalen Array zu machen.

Tschau Ingo

Offline tuxie

  • Benutzer
  • Beiträge: 6.830
  • Falcon! Milan! Schuetzt die Raubvoegel!
Re: mehrdimensionale Array
« Antwort #3 am: Sa 16.08.2008, 10:55:57 »
Erhalte diese Fehlermedlungen!

bounce' which is not static
xlbios.c: At top level:
xlbios.c:99: warning: data definition has no type or storage class
xlbios.c:99: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:99: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:99: error: invalid initializer
xlbios.c:100: warning: data definition has no type or storage class
xlbios.c:100: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:100: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:100: error: invalid initializer
xlbios.c:101: warning: data definition has no type or storage class
xlbios.c:101: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:101: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:101: error: invalid initializer
xlbios.c:102: warning: data definition has no type or storage class
xlbios.c:102: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:102: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:102: error: invalid initializer
xlbios.c:103: warning: data definition has no type or storage class
xlbios.c:103: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:103: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:103: error: invalid initializer
xlbios.c:104: warning: data definition has no type or storage class
xlbios.c:104: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:104: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:104: error: invalid initializer
xlbios.c:106: warning: data definition has no type or storage class
xlbios.c:106: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:106: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:106: error: invalid initializer
xlbios.c:107: warning: data definition has no type or storage class
xlbios.c:107: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:107: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:107: error: invalid initializer
xlbios.c:108: warning: data definition has no type or storage class
xlbios.c:108: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:108: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:108: error: invalid initializer
xlbios.c:109: warning: data definition has no type or storage class
xlbios.c:109: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:109: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:109: error: invalid initializer
xlbios.c:110: warning: data definition has no type or storage class
xlbios.c:110: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:110: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:110: error: invalid initializer
xlbios.c:111: warning: data definition has no type or storage class
xlbios.c:111: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:111: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:111: error: invalid initializer
xlbios.c:114: warning: data definition has no type or storage class
xlbios.c:114: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:114: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:114: error: invalid initializer
xlbios.c:115: warning: data definition has no type or storage class
xlbios.c:115: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:115: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:115: error: invalid initializer
xlbios.c:116: warning: data definition has no type or storage class
xlbios.c:116: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:116: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:116: error: invalid initializer
xlbios.c:117: warning: data definition has no type or storage class
xlbios.c:117: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:117: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:117: error: invalid initializer
xlbios.c:118: warning: data definition has no type or storage class
xlbios.c:118: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:118: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:118: error: invalid initializer
xlbios.c:119: warning: data definition has no type or storage class
xlbios.c:119: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:119: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:119: error: invalid initializer
xlbios.c:121: warning: data definition has no type or storage class
xlbios.c:121: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:121: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:121: error: invalid initializer
xlbios.c:122: warning: data definition has no type or storage class
xlbios.c:122: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:122: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:122: error: invalid initializer
xlbios.c:123: warning: data definition has no type or storage class
xlbios.c:123: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:123: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:123: error: invalid initializer
xlbios.c:124: warning: data definition has no type or storage class
xlbios.c:124: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:124: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:124: error: invalid initializer
xlbios.c:125: warning: data definition has no type or storage class
xlbios.c:125: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:125: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:125: error: invalid initializer
xlbios.c:126: warning: data definition has no type or storage class
xlbios.c:126: warning: type defaults to 'int' in declaration of 'stry'
xlbios.c:126: error: conflicting types for 'stry'
xlbios.c:98: error: previous declaration of 'stry' was here
xlbios.c:126: error: invalid initializer
xlbios.c: In function 'main':
xlbios.c:180: warning: suggest parentheses around assignment used as truth value

Das Array sieht jetzt so aus, die Zeile 98 ist char* stry....

char* stry[4][6];
stry[1][1] = "Qme4.04";
stry[1][2] = "XL-OS";
stry[1][3] = "SPEEDER-OS";
stry[1][4] = "OLD-OS BIBOMON";
stry[1][5] = "OmniMon";
stry[1][6] = "OmniView";

stry[2][1] = "AUS";
stry[2][2] = "256KB RAMBO";
stry[2][3] = "256KB COMPYSHOP";
stry[2][4] = "512KB RAMBO";
stry[2][5] = NULL;
stry[2][6] = NULL;

stry[3][1] = "STANDART MONO";
stry[3][2] = "STEREO";
stry[3][3] = NULL;
stry[3][4] = NULL;
stry[3][5] = NULL;
stry[3][6] = NULL;

stry[4][1] = "KALTSTART";
stry[4][2] = "WARMSTART";
stry[4][3] = NULL;
stry[4][4] = NULL;
stry[4][5] = NULL;
stry[4][6] = NULL;

Edit: habs gefunden, mußte natürlich ins Hauptprogarmm rein :-)
Weiß irgendwie nicht weiter, da C für mich auch Neuland ist aber ichs auch lernen möchte.

Danke schonmal im Vorraus.
« Letzte Änderung: Sa 16.08.2008, 11:20:40 von tuxie »
Tschau Ingo

Offline tuxie

  • Benutzer
  • Beiträge: 6.830
  • Falcon! Milan! Schuetzt die Raubvoegel!
Re: mehrdimensionale Array
« Antwort #4 am: Sa 16.08.2008, 11:24:25 »
Bekomme aber jetzt diese Fehlermeldung


xlbios.c:219: warning: passing argument 4 of 'menuzeichnen' from incompatible pointer type

Der Aufruf im Hauptprogramm

menuzeichnen(menux, menuy, menustr, stry);

void menuzeichnen(int x, int y, char* menustr[], const char ** stry)

menustr sieht so aus.

char str1[] = "BETRIEBSSYSTEME";
char str2[] = "SPEICHERCONFIG";
char str3[] = "SOUNDCONFIG";
char str4[] = "RESET";
 
char* menustr[] = {
  str1,
  str2,
  str3,
  str4
};
Tschau Ingo

Offline AltF4

  • Benutzer
  • Beiträge: 49
Re: mehrdimensionale Array
« Antwort #5 am: Sa 16.08.2008, 23:54:01 »
Hm, irgendwie ist mir jetzt auch nicht so recht klar, wieso das so nicht geht...

Auf jeden Fall compiliert das folgende Beispiel mit dem gcc und lässt sich auch problemlos ausführen:

#include <stdio.h>
#ifndef  NULL
# define NULL ((void*)0)
#endif

char str1[] = "BETRIEBSSYSTEME";
char str2[] = "SPEICHERCONFIG";
char str3[] = "SOUNDCONFIG";
char str4[] = "RESET";
 
char* menustr[] = {
  str1,
  str2,
  str3,
  str4
};

void menuzeichnen(int x, int y, char* menustr[], const char * stry[][6])
{
int i, j;
printf ("-----------------------------------\n");
for (i = 0; i < 4; i++) {
for (j = 0; j < sizeof(*stry)/sizeof(**stry); j++) {
if (stry[i][j] != NULL) {
printf("%s\n", stry[i][j]);
}
}
printf ("-----------------------------------\n");
}
}

main (void)
{
const char* stry[][6] = {
{ "Qme4.04", "XL-OS", "SPEEDER-OS", "OLD-OS BIBOMON", "OmniMon", "OmniView" },
{ "AUS", "256KB RAMBO", "256KB COMPYSHOP", "512KB RAMBO", NULL, NULL },
{ "STANDART MONO", "STEREO", NULL, NULL, NULL, NULL },
{ "KALTSTART", "WARMSTART", NULL, NULL, NULL, NULL }
};
menuzeichnen(1, 2, menustr, stry);
}

Vielleicht hilft Dir das ja weiter.

Gruß,
Ralph

Offline tuxie

  • Benutzer
  • Beiträge: 6.830
  • Falcon! Milan! Schuetzt die Raubvoegel!
Re: mehrdimensionale Array
« Antwort #6 am: So 17.08.2008, 00:17:38 »
Hi,

danke für die Tips es lag an der Typdefinition in der Funktion, jetzt funzt es aber der µC will nichtmehr hat sich wohl gehimmelt  ???

Tschau Ingo