verschieden e probs

Schnelle objektorientierte, kompilierende Programmiersprache.
Antworten
Empire
Beiträge: 272
Registriert: Mo Jan 26, 2009 5:36 pm

verschieden e probs

Beitrag von Empire » Fr Jun 26, 2009 4:37 pm

Allso das hab ich:

Code: Alles auswählen

#include <stdio.h>
#include "pi.c"

char wort1 [25], wort2 [25], wort3 [25], wort4 [25], wort5 [25], wort6 [25], wort7 [25], wort8 [25], wort9 [25], wort10 [25], wort11 [25], wort12 [25], wort13 [25], wort14 [25], wort15 [25], wort16 [25], wort17 [25], wort18 [25], wort19 [25], wort20 [25], wort21 [25], wort22 [25], wort23 [25], wort24 [25], wort25 [25];

int main ()
{
  pi();
  printf ("hi");
  return 0;
}
und

Code: Alles auswählen

#include <stdio.h>

void pi()
{
  if (wort1=="Pi") goto ja;
  if (wort2=="Pi") goto ja;
  if (wort3=="Pi") goto ja;
  if (wort4=="Pi") goto ja;
  if (wort5=="Pi") goto ja;
  if (wort6=="Pi") goto ja;
  if (wort7=="Pi") goto ja;
  if (wort8=="Pi") goto ja;
  if (wort9=="Pi") goto ja;
  if (wort10=="Pi") goto ja;
  if (wort11=="Pi") goto ja;
  if (wort12=="Pi") goto ja;
  if (wort13=="Pi") goto ja;
  if (wort14=="Pi") goto ja;
  if (wort15=="Pi") goto ja;
  if (wort16=="Pi") goto ja;
  if (wort17=="Pi") goto ja;
  if (wort18=="Pi") goto ja;
  if (wort19=="Pi") goto ja;
  if (wort20=="Pi") goto ja;
  if (wort21=="Pi") goto ja;
  if (wort22=="Pi") goto ja;
  if (wort23=="Pi") goto ja;
  if (wort24=="Pi") goto ja;
  if (wort25=="Pi") goto ja;
  else goto nein;
  ja:
  pij()

  nein:
}

void pij()
{
  if (wort1=="wie") goto ja2;
  if (wort2=="wie") goto ja2;
  if (wort3=="wie") goto ja2;
  if (wort4=="wie") goto ja2;
  if (wort5=="wie") goto ja2;
  if (wort6=="wie") goto ja2;
  if (wort7=="wie") goto ja2;
  if (wort8=="wie") goto ja2;
  if (wort9=="wie") goto ja2;
  if (wort10=="wie") goto ja2;
  if (wort11=="wie") goto ja2;
  if (wort12=="wie") goto ja2;
  if (wort13=="wie") goto ja2;
  if (wort14=="wie") goto ja2;
  if (wort15=="wie") goto ja2;
  if (wort16=="wie") goto ja2;
  if (wort17=="wie") goto ja2;
  if (wort18=="wie") goto ja2;
  if (wort19=="wie") goto ja2;
  if (wort20=="wie") goto ja2;
  if (wort21=="wie") goto ja2;
  if (wort22=="wie") goto ja2;
  if (wort23=="wie") goto ja2;
  if (wort24=="wie") goto ja2;
  if (wort25=="wie") goto ja2;
  else goto nein2;

  ja2:
  if (wort1=="groß") goto ja3;
  if (wort2=="groß") goto ja3;
  if (wort3=="groß") goto ja3;
  if (wort4=="groß") goto ja3;
  if (wort5=="groß") goto ja3;
  if (wort6=="groß") goto ja3;
  if (wort7=="groß") goto ja3;
  if (wort8=="groß") goto ja3;
  if (wort9=="groß") goto ja3;
  if (wort10=="groß") goto ja3;
  if (wort11=="groß") goto ja3;
  if (wort12=="groß") goto ja3;
  if (wort13=="groß") goto ja3;
  if (wort14=="groß") goto ja3;
  if (wort15=="groß") goto ja3;
  if (wort16=="groß") goto ja3;
  if (wort17=="groß") goto ja3;
  if (wort18=="groß") goto ja3;
  if (wort19=="groß") goto ja3;
  if (wort20=="groß") goto ja3;
  if (wort21=="groß") goto ja3;
  if (wort22=="groß") goto ja3;
  if (wort23=="groß") goto ja3;
  if (wort24=="groß") goto ja3;
  if (wort25=="groß") goto ja3;
  else goto nein2;

  ja3:
  printf ("Pi beträgt 3,141592654");
  nein2:
}
und jetzt das prob:

Code: Alles auswählen

E:\BOT\pi.c||In function `pi':|
E:\BOT\pi.c|5|error: `wort1' undeclared (first use in this function)|
E:\BOT\pi.c|5|error: (Each undeclared identifier is reported only once|
E:\BOT\pi.c|5|error: for each function it appears in.)|
E:\BOT\pi.c|6|error: `wort2' undeclared (first use in this function)|
E:\BOT\pi.c|7|error: `wort3' undeclared (first use in this function)|
E:\BOT\pi.c|8|error: `wort4' undeclared (first use in this function)|
E:\BOT\pi.c|9|error: `wort5' undeclared (first use in this function)|
E:\BOT\pi.c|10|error: `wort6' undeclared (first use in this function)|
E:\BOT\pi.c|11|error: `wort7' undeclared (first use in this function)|
E:\BOT\pi.c|12|error: `wort8' undeclared (first use in this function)|
E:\BOT\pi.c|13|error: `wort9' undeclared (first use in this function)|
E:\BOT\pi.c|14|error: `wort10' undeclared (first use in this function)|
E:\BOT\pi.c|15|error: `wort11' undeclared (first use in this function)|
E:\BOT\pi.c|16|error: `wort12' undeclared (first use in this function)|
E:\BOT\pi.c|17|error: `wort13' undeclared (first use in this function)|
E:\BOT\pi.c|18|error: `wort14' undeclared (first use in this function)|
E:\BOT\pi.c|19|error: `wort15' undeclared (first use in this function)|
E:\BOT\pi.c|20|error: `wort16' undeclared (first use in this function)|
E:\BOT\pi.c|21|error: `wort17' undeclared (first use in this function)|
E:\BOT\pi.c|22|error: `wort18' undeclared (first use in this function)|
E:\BOT\pi.c|23|error: `wort19' undeclared (first use in this function)|
E:\BOT\pi.c|24|error: `wort20' undeclared (first use in this function)|
E:\BOT\pi.c|25|error: `wort21' undeclared (first use in this function)|
E:\BOT\pi.c|26|error: `wort22' undeclared (first use in this function)|
E:\BOT\pi.c|27|error: `wort23' undeclared (first use in this function)|
E:\BOT\pi.c|28|error: `wort24' undeclared (first use in this function)|
E:\BOT\pi.c|29|error: `wort25' undeclared (first use in this function)|
E:\BOT\pi.c|34|error: syntax error before "nein"|
E:\BOT\pi.c|30|error: label `nein' used but not defined|
E:\BOT\pi.c|38|error: conflicting types for 'pij'|
E:\BOT\pi.c|32|error: previous implicit declaration of 'pij' was here|
E:\BOT\pi.c||In function `pij':|
E:\BOT\pi.c|39|error: `wort1' undeclared (first use in this function)|
E:\BOT\pi.c|40|error: `wort2' undeclared (first use in this function)|
E:\BOT\pi.c|41|error: `wort3' undeclared (first use in this function)|
E:\BOT\pi.c|42|error: `wort4' undeclared (first use in this function)|
E:\BOT\pi.c|43|error: `wort5' undeclared (first use in this function)|
E:\BOT\pi.c|44|error: `wort6' undeclared (first use in this function)|
E:\BOT\pi.c|45|error: `wort7' undeclared (first use in this function)|
E:\BOT\pi.c|46|error: `wort8' undeclared (first use in this function)|
E:\BOT\pi.c|47|error: `wort9' undeclared (first use in this function)|
E:\BOT\pi.c|48|error: `wort10' undeclared (first use in this function)|
E:\BOT\pi.c|49|error: `wort11' undeclared (first use in this function)|
E:\BOT\pi.c|50|error: `wort12' undeclared (first use in this function)|
E:\BOT\pi.c|51|error: `wort13' undeclared (first use in this function)|
E:\BOT\pi.c|52|error: `wort14' undeclared (first use in this function)|
E:\BOT\pi.c|53|error: `wort15' undeclared (first use in this function)|
E:\BOT\pi.c|54|error: `wort16' undeclared (first use in this function)|
E:\BOT\pi.c|55|error: `wort17' undeclared (first use in this function)|
E:\BOT\pi.c|56|error: `wort18' undeclared (first use in this function)|
E:\BOT\pi.c|57|error: `wort19' undeclared (first use in this function)|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 0 warnings ===|
ICH HASSE CODEBLOCKS!!!
was will der mist von mir:
die vari sind global...
die funktionen gibts...


mfg
Empire

Benutzeravatar
cloidnerux
Moderator
Beiträge: 3125
Registriert: Fr Sep 26, 2008 4:37 pm
Wohnort: Ram (Gibts wirklich)

Re: verschieden e probs

Beitrag von cloidnerux » Fr Jun 26, 2009 4:46 pm

Du musst verstehen wo Variablen Deklariert werden.
Diene Funktion pi wird VOR den Vraiablen Eingebunden und auch vor den Variablen Compiliert, dessahlb kennt es sie nicht.
Dasselbe gilt für Funktionen. Zumindest ein Funktionsdummy muss VOR der ersten Verwendung deklariert worden sein.

Zum anderen solltest du dir wirklich mal ein ordentliches Buch zum Thema Programmieren kaufen.
goto ist keine lösung, sondern eine zumutung.
Konstrukte wie:
if(true) goto nein;
...
nein:
}

kann mna mit

Code: Alles auswählen

if(true) return;
Lösen.
Statt 25 Variablen kann man ein Array ertellen, das man in einer Schleife abfragt, etwa so:

Code: Alles auswählen

char meineWörter[25][25]
Das erstellt 25 Charaarrys der Länge 25.
und mit

Code: Alles auswählen

for(int i= 0; i< 25, i++)
{
   if(meineWörter[i] == "Wie") return;
}
Oder so.
ich habe hier eine C++ Notatiopn im If verwendet, du müsstest das bei dir gegebenfalls anpassen.
Redundanz macht wiederholen unnötig.
quod erat expectandum

Benutzeravatar
Xin
nur zu Besuch hier
Beiträge: 8862
Registriert: Fr Jul 04, 2008 11:10 pm
Wohnort: /home/xin
Kontaktdaten:

Re: verschieden e probs

Beitrag von Xin » Fr Jun 26, 2009 5:06 pm

Moin Empire...

Ich weiß nicht, von wo Du Deine Informationen zu C herholst, aber ich bitte Dich dringenst: Such sie Dir wo anders!
Dein hier vorgestellter Quelltext ist ein Gruselkabinett für C-Programmierer. Das sieht aus, als würdest Du die sieben Totsünden der C-Programmierung wiedergeben wollen.
Empire hat geschrieben:Allso das hab ich:

Code: Alles auswählen

#include <stdio.h>
#include "pi.c"
Binde keinen C-Quelltext per Include ein.
Wenn Du mehrere Dateien nutzt, mach ein Projekt auf!
Empire hat geschrieben:

Code: Alles auswählen

char wort1 [25], wort2 [25], wort3 [25], wort4 [25], wort5 [25], wort6 [25], wort7 [25], wort8 [25], wort9 [25], wort10 [25], wort11 [25], wort12 [25], wort13 [25], wort14 [25], wort15 [25], wort16 [25], wort17 [25], wort18 [25], wort19 [25], wort20 [25], wort21 [25], wort22 [25], wort23 [25], wort24 [25], wort25 [25];
Ich hbae Dir im letzten Thread schon gesagt, dass Du Arrays verwenden sollst:

Code: Alles auswählen

char ** worte;
int const wortAnzahl  = 25;
int const wortLaenge = 25;

worte = new char *[wortAnzahl];
for( int i = 0; i < wortAnzahl; i++ )
  worte[i] = new char[wortlaenge];
Empire hat geschrieben: und

Code: Alles auswählen

#include <stdio.h>

void pi()
{
  if (wort1=="Pi") goto ja;
  if (wort2=="Pi") goto ja;
  if (wort3=="Pi") goto ja;
  if (wort4=="Pi") goto ja;
  if (wort5=="Pi") goto ja;
  if (wort6=="Pi") goto ja;
  if (wort7=="Pi") goto ja;
  if (wort8=="Pi") goto ja;
  if (wort9=="Pi") goto ja;
  if (wort10=="Pi") goto ja;
  if (wort11=="Pi") goto ja;
  if (wort12=="Pi") goto ja;
  if (wort13=="Pi") goto ja;
  if (wort14=="Pi") goto ja;
  if (wort15=="Pi") goto ja;
  if (wort16=="Pi") goto ja;
  if (wort17=="Pi") goto ja;
  if (wort18=="Pi") goto ja;
  if (wort19=="Pi") goto ja;
  if (wort20=="Pi") goto ja;
  if (wort21=="Pi") goto ja;
  if (wort22=="Pi") goto ja;
  if (wort23=="Pi") goto ja;
  if (wort24=="Pi") goto ja;
  if (wort25=="Pi") goto ja;
  else goto nein;
  ja:
  pij()

  nein:
}
Ich werde Dir diese Funktion jetzt umschreiben. Dananch werde ich diese Goto-Katastrophen nicht mehr kommentieren. Es macht einfach keinen Sinn, Dich jedesmal darauf hinzuweisen, dass goto für Dich ein Tabu zu sein hat.
Auch auf strcmp hbae ich Dich bereits im vorherigen Post hingewiesen. Wenn Du Hilfe suchst, dann musst Du das auch annehmen. Wir helfen gerne, Deinen Code und Deinen Stil zu verbessern, aber es ist nicht die Aufgabe schlechten Stil irgendwie lauffähig zu bekommen.
Der Vergleich wort1=="Pi" wird immer false ergeben.

Code: Alles auswählen

void pi()
{
  for(int i = 0; i<=wortAnzahl; i++)
    if( !strcmp( wort[i], "Pi" )
    {
      pij();
      break;
    }
}
Diese Funktion macht das gleiche wie die, die Du geschrieben hast... nur lesbar, strukturiert (also komplett ohne goto).
Du solltest weiterhin die Funktionsnamen überdenken. Du kannst diese Funktion hier nun auch anders nutzen:

Code: Alles auswählen

char woerterEnthalten( char * vergleichsWort )
{
  for(int i = 0; i<=wortAnzahl; i++)
    if( !strcmp( wort[i], vergleichsWort ) )
      return 1;

  return 0;
}

int main()
{
  ...
  if( woerterEnthalten( "Hallo" ) )
    printf( "Wort 'Hallo' gefunden\n");
else
    printf( "Wort 'Hallo' NICHT gefunden\n");
  ...
}
Die Funktion woerterEnthalten alleine kann Deine ganzen endlosen if...goto reihen ablösen.
Mit Goto kannst Du quer durch das Programm springen und bei Deiner Copy'n'Paste-Programmierung ist das sehr wahrscheinlich, dass genau das passieren wird.
Empire hat geschrieben: und jetzt das prob:

Code: Alles auswählen

E:\BOT\pi.c||In function `pi':|
E:\BOT\pi.c|5|error: `wort1' undeclared (first use in this function)|
Du bindest Quelltext per #include ein und greifst dort auf Variablen zu, die zu dem Zeitpunkt noch nicht definiert sind.

Empire hat geschrieben:

Code: Alles auswählen

E:\BOT\pi.c|34|error: syntax error before "nein"|
E:\BOT\pi.c|30|error: label `nein' used but not defined|
Semikolon vergessen.
Empire hat geschrieben:ICH HASSE CODEBLOCKS!!!
was will der mist von mir:
die vari sind global...
die funktionen gibts...
Nicht zu dem Zeitpunkt, an dem Du die Variablen benutzt. Quelltext ist ein Buch, das so runtergelesen wird und wenn er pi.c liest, gibt es keine globalen Variablen.

Nochmals: Du MUSST Deinen Programmierstil ändern, das hier geht gar nicht.
Bitte such Dir ein brauchbares C Buch und fang an zu lernen, bevor Du etwas derartiges programmierst.
Merke: Wer Ordnung hellt ist nicht zwangsläufig eine Leuchte.

Ich beantworte keine generellen Programmierfragen per PN oder Mail. Dafür ist das Forum da.

Empire
Beiträge: 272
Registriert: Mo Jan 26, 2009 5:36 pm

Re: verschieden e probs

Beitrag von Empire » So Jun 28, 2009 3:50 pm

Ich versuchs
ZU goto ich hab euch schon mindstesns 2 mal gebeten das nicht mehr zu kommentieren.

ansonstens danke
Vorallem das mir dem buch hat mir geholfen

mfg
Empire

Benutzeravatar
Xin
nur zu Besuch hier
Beiträge: 8862
Registriert: Fr Jul 04, 2008 11:10 pm
Wohnort: /home/xin
Kontaktdaten:

Re: verschieden e probs

Beitrag von Xin » Mo Jun 29, 2009 12:17 am

Empire hat geschrieben:Ich versuchs
ZU goto ich hab euch schon mindstesns 2 mal gebeten das nicht mehr zu kommentieren.
Sorry, das wird sich bereits kurzfristig als ein größeres Problem herausstellen als die Tatsache, dass es nicht kompiliert.

Wenn Du programmieren möchtest, dann ist die Vermeidung von goto derzeit der Punkt, dem Du die höchste Priorität geben musst.
Merke: Wer Ordnung hellt ist nicht zwangsläufig eine Leuchte.

Ich beantworte keine generellen Programmierfragen per PN oder Mail. Dafür ist das Forum da.

Antworten