Convertir code C en delphi
Salut, j'aurais besoin d'aide, car j'ai trouvé ce code en C et j'en ai absolument besoin pour mon programme en Delphi, cependant, je ne connait pas grand chose au C, et je n'arrive pas à convertir ce code, car je ne trouve pas d'équivalent delphi aux fonction utilisée.
Sa serait sympas si quelqu'un pouvait m'aider, merci.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <stdio.h>
#include <stdlib.h>
#define SIGN_START 0x800
#define SIG_POS 0x2d0
#define INIT_SUM 0x00000000
int main(int argc, char **argv)
{
FILE *fp;
int sum, buf;
if (argc != 2) {
printf("Bad args. should be %s <mapfile>\n", argv[0]);
exit(0);
}
if (!(fp = fopen(argv[1], "r+"))) {
printf("Error opening file.\n");
exit(0);
}
// initialize xor sum
sum = INIT_SUM;
// go to start of hash
fseek(fp, SIGN_START, SEEK_SET);
// assuming 4 byte ints.
while (!feof(fp)) {
fread(&buf, sizeof(int), 1, fp);
sum = sum ^ buf;
}
sum = sum ^ buf;
clearerr(fp);
fseek(fp, SIG_POS, SEEK_SET);
fwrite(&sum, sizeof(int), 1, fp);
fclose(fp);
} |
Re: Convertir code C en delphi
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
// Définition des constantes
#define SIGN_START 0x800
#define SIG_POS 0x2d0
#define INIT_SUM 0x00000000
// fonction principale en C, char argv a l'air d'être comme le paramstr().
int main(int argc, char **argv)
{
FILE *fp; // variable TFileStream
int sum, buf; // définition de variables
if (argc != 2) { // si argc <> 2 alors
printf("Bad args. should be %s <mapfile>\n", argv[0]); // affchage si <> 2
exit(0); // sortir de la fonction
}
if (!(fp = fopen(argv[1], "r+"))) { // ouverture du TFileStream
printf("Error opening file.\n");
exit(0);
}
// initialize xor sum
sum = INIT_SUM;
// go to start of hash
fseek(fp, SIGN_START, SEEK_SET);// se positionner dans le fichier (utiliser Seek)
// assuming 4 byte ints.
while (!feof(fp)) { // boucle de récupération des données jusqu'à qu'on arrive en fin de fichier
fread(&buf, sizeof(int), 1, fp); // Utiliser ReadBuffer pour la lecture dans le fichier
sum = sum ^ buf;
}
sum = sum ^ buf;
// Ecrit la somme a la position SIG_POS dans le fichier
clearerr(fp);
fseek(fp, SIG_POS, SEEK_SET);
fwrite(&sum, sizeof(int), 1, fp);
fclose(fp); // fermeture du fichier
} |