Supportnet / Forum / Anwendungen(Java,C++...)
C++ Error E2141 : Declaration syntax error in function main()
Frage
Hi friends,
ich probiere gerade ein bisschen an der RS232-Schnittstelle herum (LED blinken lassen).
Ich habe den Quelltext und die cport.h aus dem Internet. Leider bekomme ich beim compilen den Fehler nicht weg. Das ist bestimmt nur eine Kleinigkeit. Aber ich stehe voll auf dem Schlauch. Vielleicht kann jemand helfen.
Quelltext und cport.h als Anhang:
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <cport.h>
int main ()
{
void blinkeLED(int sek, int anz, int millisek)
{
ComPort comp; //erzeuge Objekt für Schnittstelle
comp.SetOPEN(1); //Öffne COM1 (GND hat ab jetzt Strom)
while(!kbhit()) //Prüft ob eine Taste gedrückt wurde
{
blinke(comp, anz, millisek);
sleep(sek); //wartet sek Sekunden bis es weitergeht
}
getch(); //fängt die Eingabe ab
if(kbhit()) //wenn nötig
getch(); //ein zweites mal (Sondertasten)
comp.SetCLOSE(); //Schließt Schnittstelle (Alle Pins kein Strom)
}
void blinke(ComPort comp, int anz, int millisek)
{
int i;
for(i=0;i<anz;++i)
{
comp.SetRTS(TRUE); //Strom auf RTS-Leitung (LED leuchtet)
Sleep(millisek); //wartet millisek Millisekunden bis es weitergeht
comp.SetRTS(FALSE); //Strom weg von RTS-Leitung (LED aus)
}
}
blinkeLED(1,2,100);
return(0);
}
/*
//cport.h
#define WRONG_PORT 100
#define ON true
#define OFF false
class ComPort
{
public:
int SetOPEN (int PORT);
int SetCLOSE (void);
int SetDTR (bool mode);
int SetRTS (bool mode);
int SetTXD (bool mode);
bool GetCTS ();
bool GetDSR ();
void SetAll (bool mode);
};
*/
THANKS @ all
Antwort 1 von Kai
Du erstellest Funktionen in der Main Funktion, das wird vom Compiler beanstandet.
Falsch: >>>>>>>>>>>>
int main()
{
void funktion_xyz( int a )
{
//tu was mit a
}
funktion_xyz( 1 );
return 0;
}
Richtig: >>>>>>>>>>>>
// prototyp
void funktion_xyz( int a );
int main()
{
funktion_xyz( 1 );
return 0;
}
void funktion_xyz( int a )
{
// tu was mit a
}
Falsch: >>>>>>>>>>>>
int main()
{
void funktion_xyz( int a )
{
//tu was mit a
}
funktion_xyz( 1 );
return 0;
}
Richtig: >>>>>>>>>>>>
// prototyp
void funktion_xyz( int a );
int main()
{
funktion_xyz( 1 );
return 0;
}
void funktion_xyz( int a )
{
// tu was mit a
}
Antwort 2 von Fruitloop
Thanks,
naja, das passiert halt wenn man mal 3 Jahre überhaupt nix programmiert hat.
mfg & thanks
fruitloop
naja, das passiert halt wenn man mal 3 Jahre überhaupt nix programmiert hat.
mfg & thanks
fruitloop

