Hi again guys,
I'm doing the second program for the university and I've got a problem with a comparison between characters.
The user has to choose a gamemode (E or F).
Code:
#include <stdio.h>
#include "tipus.h"
int main() {
int error;
int i = 0;
int nCorrecte = 0;
int nJugadors = 0;
char cMode;
stPlayer jugador[4];
allegro_init();
install_keyboard();
error=set_gfx_mode(GFX_SAFE, 800, 600, 0, 0);
if (error==0){
while(nCorrecte == 0){
printf("Gamemode <E o F>: ");
fflush(stdin);
scanf("%c",&cMode);
printf("%c",cMode); //That's for check if the cMode is good.
if(cMode == 'E' || cMode == 'F' || cMode == 'e' || cMode == 'f'){ //This comparison works great.
nCorrecte = 1;
}
else{
printf("Error! Mode de joc incorrecte!\n");
}
}
tauler(cMode); //Here is where I'm going to do the comparison.
}
And tauler:
Code:
void tauler(char cMode){
stCasella casella[96];
printf("%c\n",cMode); //That's for check the cMode again, it's fine.
assignaCasella(casella);
assignaEspecial(cMode, casella); //That's the function!
printaCasella(casella);
}
Code:
void assignaEspecial(char cMode, stCasella casella[96]){
FILE *f;
char strFitxer[50];
stFitxer fitxer[96];
int i = 0;
int proba = 5;
printf("%c\n",cMode); //Works!
if(cMode == 'F' ||cMode == 'f'){ //DOESN'T WORK
printf("File name?: ");
scanf("%s",strFitxer);
f = fopen(strFitxer,"r");
if( f == NULL){
printf("Error! Fitxer NULL\n");
}
else{
fscanf(f,"%c",fitxer[i].cTipus);
fscanf(f,"%d", fitxer[i].nCasella);
while(!feof){ //Llegim el fitxer
i++;
fscanf(f,"%c",fitxer[i].cTipus);
fscanf(f,"%d", fitxer[i].nCasella);
if(fitxer[i].cTipus == 'B'){
fscanf(f,"%d",fitxer[i].nTorns);
}
}
}
fclose(f);
assignaFitxer(fitxer, casella, i);
}
if(cMode == 'E' || cMode == 'e'){ //DOESN'T WORK TOO
for(i = 0; i < 96; i++){
if(i == 59 || i == 80){
casella[i].nEspecial = 2;
casella[i].nColor = 6;
}
if( i == 66 || i == 90){
casella[i].nEspecial = 3;
casella[i].nColor = 0;
}
if( i == 5 || i == 10 || i == 17 || i == 23 || i == 30 || i == 38 || i == 42 || i == 50 || i == 56 || i == 64 || i == 70 || i == 73 || i == 77 || i == 82 || i == 92){
casella[i].nEspecial = 1;
casella[i].nColor = 7;
}
}
}
}
So, what's happening?