Software > Coding

mehrdimensionale Array

(1/2) > >>

tuxie:
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.


--- Code: ---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";

--- Ende Code ---

Jetzt soll das Array an eine Funktion übergeben werden.

wie stelle ich das am besten an.

TSchau Ingo

AltF4:
Müsste eigentlich so funzen:


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

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

--- Ende Code ---

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

Gruß,
Ralph

tuxie:
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.

tuxie:
Erhalte diese Fehlermedlungen!


--- Code: ---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

--- Ende Code ---

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


--- Code: ---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;

--- Ende Code ---

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.

tuxie:
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
};

Navigation

[0] Themen-Index

[#] Nächste Seite

Zur normalen Ansicht wechseln