Code e hơi dài. Bác nào giúp e với. E không hiểu tại sao lại có lỗi ở đấy.
Nó đòi while() trước dấu } và lỗi expected primary expression cũng trước dấu }.
Lỗi ở dòng gần cuối e đã đánh dấu.
#include <stdio.h>
#include <dos.h>
#include <windows.h>
#include <math.h>
#include <stdlib.h>
//globale Variablen
int Phase1 = 0; //Ausgang Phase1
int Phase2 = 0; //Ausgang Phase2
int Phase3 = 0; //Ausgang Phase3
int POS[] = {0,500,1000,1500,2000,2500,3000,3500,4000,4096};
int runden(float n) // rundungsfunktion (weil modulo nicht mit Float funktioniert)
{
if (n-(int)(n) >= 0.5)
return (int)(n+1);
else
return (int)(n);
} //ende runden
typedef enum {Ruhe,Links,Rechts,Stop}TSTATE;
TSTATE state = Ruhe;
//Main-Funktion
int main(){
unsigned int schrittwinkel = 15;
unsigned int ausschaltwinkel = 14; // variabel
float a,p1;
unsigned int aufloesung = 4096;
float zw,KPOS1;
int KPOS = 0;
int i,b,c,d;
a = schrittwinkel*(aufloesung/360); // schrittwinkel
b = ausschaltwinkel*(aufloesung/360); // ausschaltwinkel
c = 512; // periode = 3*15*umrechungsfaktor = 512
//---------Endlosschleife begin------------------------------------------------------------------------------------
while(1){
switch (state) {
case Ruhe:
int j;
do{
printf("Drehrichtung auswählen (0 für links und 1 für rechts)");
scanf("%i",j);
if(j==0){
state = Links;
}
else if(j==1){
state = Rechts;
}
else{
printf("FEHLER!!! bitte nur 0 oder 1 eingeben ");
}
while(j<0||j>1);
break;
case Links :
zw = 48+(a-b);
for(i=0;i<=9;i++){
KPOS1 = POS* + zw;
KPOS = runden(KPOS1);
d = KPOS % c;
if(KPOS >=4096){
KPOS = KPOS - 4096;
}
printf("POS: %i
",POS*);
printf("KPOS: %i
",KPOS);
//drehender Betrieb
if((0 <= d) && (d <= a)){
Phase1 = 0;
Phase3 = 0;
Phase2 = 1;
printf("Phase1: %i
",Phase1);
printf("Phase2: %i
",Phase2);
printf("Phase3: %i
",Phase3);
printf("--------------------
");
} //ende if
if((a < d) && (d <= 2*a)){
Phase2 = 0;
Phase1 = 0;
Phase3 = 1;
printf("Phase1: %i
",Phase1);
printf("Phase2: %i
",Phase2);
printf("Phase3: %i
",Phase3);
printf("--------------------
");
} //ende if
if((2*a < d) && (d <3* a)){
Phase2 = 0;
Phase3 = 0;
Phase1 = 1;
printf("Phase1: %i
",Phase1);
printf("Phase2: %i
",Phase2);
printf("Phase3: %i
",Phase3);
printf("--------------------
");
} //ende if
} //ende for
break;
case Rechts:
zw = 48-(a-b);
for(i=0;i<=9;i++){
KPOS1 = POS* + zw;
KPOS = runden(KPOS1);
d = 512-(KPOS % c);
if(KPOS >=4096){
KPOS = KPOS - 4096;
}
printf("POS: %i
",POS*);
printf("KPOS: %i
",KPOS);
//drehender Betrieb
if((0 <= d) && (d <= a)){
Phase1 = 0;
Phase3 = 0;
Phase2 = 1;
printf("Phase1: %i
",Phase1);
printf("Phase2: %i
",Phase2);
printf("Phase3: %i
",Phase3);
printf("--------------------
");
} //ende if
if((a < d) && (d <= 2*a)){
Phase2 = 0;
Phase1 = 0;
Phase3 = 1;
printf("Phase1: %i
",Phase1);
printf("Phase2: %i
",Phase2);
printf("Phase3: %i
",Phase3);
printf("--------------------
");
} //ende if
if((2*a < d) && (d <3* a)){
Phase3 = 0;
Phase3 = 0;
Phase1 = 1;
printf("Phase1: %i
",Phase1);
printf("Phase2: %i
",Phase2);
printf("Phase3: %i
",Phase3);
printf("--------------------
");
} //ende if
} //ende for
break;
case Stop:
Phase3 = 1;
Phase3 = 1;
Phase1 = 1;
printf("Phase1: %i
",Phase1);
printf("Phase2: %i
",Phase2);
printf("Phase3: %i
",Phase3);
printf("--------------------
");
Sleep(3000);
Phase3 = 0;
Phase3 = 0;
Phase1 = 0;
printf("Phase1: %i
",Phase1);
printf("Phase2: %i
",Phase2);
printf("Phase3: %i
",Phase3);
printf("--------------------
");
state = Ruhe;
printf("***** Ruhe *****
");
printf("--------------------
");
break;
default:
state = Ruhe;
break;
} // ende switch-case
} //ende endlos while(1) Lỗi ở dòng này
return 0;
}// ende main
[/QUOTE]