Hello to everyone. I'm having some problems regarding reading specific data from a .txt file(C). I need to read, for example:
PHP Code:
1 50 5
Gabriel Stewie Stan Roger Peter
4 2
Stewie 10 12 P 5 O 6 E 8 O 5 C
Stan 7 5 E 4 C 13 O 7 O 6 C
Roger 10 6 P 2 P 5 P 3 P 4 P
Peter 2 7E 3C 2E 1O 9P
But I need to put each data into a single variable. I've thought about using something like:
Code:
do
{
...
}while (!feof(p)); /* || c !=' ' || c*!='\n'[/PHP]
But it is not working at all.. If anyone has any idea of how getting this to work, I'll be glad to try it ^^
Another thing.. While the file reading part is not ready, I'm trying to build the rest of my code using scanf(...). This is the code so far:
[PHP]int main()
{
int n, jog, rjog, di, pin, dround;
int i,j,k,card,auxjog;
char nom[30];
Jogador player[5], aux, vencedor;
printf("Rodadas:");
scanf("%d",&n);
printf("dinheiro inicial:");
scanf("%d",&di);
printf("nº de jogadores:");
scanf("%d",&jog);
for (j=0; j<jog; j++)
{
printf("nome jogador %d:",j+1);
scanf("%s",player[j].nome);
player[j].dtotal=di;
}
for (i=1; i<=n; i++)
{
printf("jogadores da rodada:");
scanf("%d",&rjog);
printf("pingo:");
scanf("%d",&pin);
dround=0;
for (j=0; j<jog; j++)
{
if (player[j].dtotal<=pin)
{
player[j].dtotal=player[j].dtotal-pin;
dround=dround+pin;
}
else if (player[j].dtotal!=0)
{
dround=dround+player[j].dtotal;
player[j].dtotal=0;
}
}
for (j=0; j<rjog; j++)
{
printf("nome jogador %d:",j+1);
scanf("%s",nom);
for (k=0; k<rjog; k++)
{
auxjog=0;
if (player[k].nome==nom)
{
player[auxjog]=aux;
player[k]=player[auxjog];
aux=player[k];
auxjog=auxjog+1;
}
}
for (card=0; card<=4; card++)
{
printf("Carta %d:",card+1);
scanf("%d",player[j].carta[card].numero);
printf("Naipe da carta %d:",card+1);
scanf("%c",player[j].carta[card].naipe);
}
}
}
return 0;
}
Code:
typedef struct carta
{
int numero;
char naipe;
}Carta;
typedef struct jogador
{
char nome[30];
Carta carta[5];
int dtotal;
int aposta;
}Jogador;
It is not ready yet, but I'm having some problems on the last "for" of main.c. Any ideas?
By the way, if anyone hasn't noticed yed, I'm kinda new to C.. ^^'