Ciao!
Ho fatto un programma che legge random da un file.txt, dove ci sono un elenco di parole, due parole prese in un ordine qualsiasi.. solo che quando lo vado ad eseguire c'è qualcosa che non va..
Ecco il codice chi mi sa aiutare gentilmente?
codice:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fpr;
int righe = 0;
printf("Quante squadre ci sono?\n");
scanf("%d", &righe);
char string[righe][100];
int i=0; int random = 0; int random2 = 0;
if ( ( fpr = fopen("file.txt","r")) == NULL)
{
printf("Il file non può essere aperto");
}
else
{
while( !feof(fpr) )
{
fgets(string[i], 1 , fpr);
i++;
}
fclose(fpr);
}
srand(time(NULL));
random = rand() % (righe +1);
system("PAUSE");
random2 = rand() % (righe +1);
if(random2 == random);
random2 = rand() % (righe +1);
printf("Prima estratta: %s", string[random]);
printf("Seconda estratta: %s", string[random2]);
return 0;
}
Ringrazio in anticipo