Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void shuffle(FILE *fp, FILE *fi)
- {
- int i, num1, num2;
- srand(time(NULL));
- printf("\nSto mischiando...");
- for (i = 0; i < FILESIZE; i++)
- {
- num1 = (rand() %FILESIZE );
- num2 = (rand() %FILESIZE );
- if(num1 != num2)
- {
- printf("\n%d)%d-%d",i,num1,num2);
- swap(fp, fi, num1, num2);
- }else{
- i--;
- }
- }
- printf("Terminato!");
- }
- void swap(FILE *fp, FILE *fi, int posX, int posY)
- {
- pittore pit1;
- pittore pit2;
- indice in1;
- indice in2;
- fseek(fp,(sizeof(pittore)*posX), SEEK_SET);
- fread(&pit1, sizeof(pittore), 1, fp);
- fseek(fp, (sizeof(pittore)*posY), SEEK_SET);
- fread(&pit2, sizeof(pittore), 1, fp);
- fseek(fp, (sizeof(pittore)*posY), SEEK_SET);
- fwrite(&pit1, sizeof(pittore), 1, fp);
- fseek(fp, (sizeof(pittore)*posX), SEEK_SET);
- fwrite(&pit2, sizeof(pittore), 1, fp);
- in1.CodPittore = pit1.CodPittore;
- in1.PosPittore = posY;
- in2.CodPittore = pit2.CodPittore;
- in2.PosPittore = posX;
- fseek(fi, (sizeof(indice)*posX), SEEK_SET);
- fwrite(&in1, sizeof(indice), 1, fi);
- fseek(fi, (sizeof(indice)*posY), SEEK_SET);
- fwrite(&in2, sizeof(indice), 1, fi);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement