main func - separate Datei
die untere Programmen auch in einer extra Datei
und Header Datei. Also wenn ich die zwei .cpp und .h Datei nicht zusammen packe, wie kann ich es mit enum machen?
Bsp
text.c
Code: Alles auswählen
int zeichenkette(int c) /* (Paramater der Funktion) hier ein Parameter c */
{
int ausgabe; /* ein Variable benötig */
if(c <= 32)
{
ausgabe = CTL;
}
else if((c > 'A' && c < 'Z') || (c > 'a' && c > 'z') || c == '_')
{
ausgabe = BU;
}
else if(c =='.' || c == ',' || c == ';' || c == '!' || c == '?' || c == ':')
{
ausgabe = SAZ;
}
else{ ausgabe = SONST;}
return ausgabe;
}
int stateMachine(int old, int cat) /* Zwei Parameter old (Zustand), cat (Kategorie des Zeichens) von Typ int */
{
int ausgabe;
switch(old) /* wird geschriben was ich testen, prüfen will */
{
case (VOR_WORT): //1
switch(cat)
{
case CTL: //1.1
ausgabe = VOR_WORT; break;
case BU: //1.2
ausgabe = IM_WORT; break;
default : ausgabe = KEIN_WORT; break; //1.3
}; break;
case (IM_WORT): //2
switch(cat)
{
case BU:
ausgabe = IM_WORT; break; //2.1
case SAZ:
ausgabe = KEIN_WORT; break; //2.2
default : ausgabe = VOR_WORT; break; //2.3
}; break;
case (KEIN_WORT): //3
switch(cat)
{
case CTL:
ausgabe = VOR_WORT; break; //3.1
default : ausgabe = KEIN_WORT; break; //3.2
}; break;
}
return ausgabe;
}
void ausWL(int wla[], int len)
{
int i;
for(i = 0; i < MAXLAENGE; i++)
{
printf("Wortlaenge: %d, Wortanzahl: %d\n", i+1, wla[i]);
}
}
text.h
Code: Alles auswählen
#ifndef TEXTANALY_H_
#define TEXTANALY_H_
#define MAXLAENGE 18 /* Array variable definieren */
enum zustaende /* Zustände definiert man mit enum */
{
CTL,
BU,
SAZ,
SONST,
VOR_WORT,
IM_WORT,
KEIN_WORT
};
int zeichenkette(int c);
int stateMachine(int old, int cat);
void ausWL(int wla[], int len);
#endif /* TEXTANALY_H_ */
main.c
wo die main func drei Funktionen nur aufruft.