• 22 Avril 2025, 14:33:42


Auteur Sujet: Problème de lecture de fichier  (Lu 821 fois)

0 Membres et 1 Invité sur ce sujet

Hors ligne vardanega

  • *
  • Tueur en série
  • http://vvardanega.wordpress.com (mon blogue)
  • Messages: 155
    • Voir le profil
Problème de lecture de fichier
« le: 04 Novembre 2010, 23:08:56 »
Bonsoir, je suis actuellement en train de faire (du moins essayer ) un système d'essence pour mon serveur. J'utilise un fichier pour chargé les positions des stations essences, Produits, Produits Max ect ..., mais quand le fichier sauvegarde (Ce met a jour) il semble y avoir un problème car tout et mélangé et lors du lancement suivant du GM tout et beugé.

Voici les codes:


<?php

enum StationSysteme
{
sName[64],
Float:sPosX,
Float:sPosY,
Float:sPosZ,
Float:sLivX,
Float:sLivY,
Float:sLivZ,
sProduits,
sMaxProduits,
sCaisse
}
new 
StationInfo[9][StationSysteme];

forward LoadStation();
public 
LoadStation()
{
new string[256];
        new 
arrCoords[10][256];
        new 
strFromFile2[256];
        new 
Filefile fopen("station.txt"io_read);
        if (
file)
        {
            
new idx;
            
idx 0;
                while (
idx sizeof(StationInfo))
                {
            
fread(filestrFromFile2);
                        
split(strFromFile2arrCoords'|');
                        
strmid(StationInfo[idx][sName], arrCoords[0], 0strlen(arrCoords[0]), 255);
StationInfo[idx][sPosX] = floatstr(arrCoords[1]);
StationInfo[idx][sPosY] = floatstr(arrCoords[2]);
StationInfo[idx][sPosZ] = floatstr(arrCoords[3]);
StationInfo[idx][sLivX] = floatstr(arrCoords[4]);
StationInfo[idx][sLivY] = floatstr(arrCoords[5]);
StationInfo[idx][sLivZ] = floatstr(arrCoords[6]);
StationInfo[idx][sProduits] = strval(arrCoords[7]);
StationInfo[idx][sMaxProduits] = strval(arrCoords[8]);
StationInfo[idx][sCaisse] = strval(arrCoords[9]);

Create3DTextLabel("|POINT DE LIVRAISON|\nUtiliser /vider"COLOR_ADMINStationInfo[idx][sLivX], StationInfo[idx][sLivY], StationInfo[idx][sLivZ], 5.000);
  AddStaticPickup(12251StationInfo[idx][sPosX], StationInfo[idx][sPosY], StationInfo[idx][sPosZ], -1);
 
  format(stringsizeof(string), "NOM: \n%s\nProduits: %d/%d\nBesoin de: %d"StationInfo[idx][sName],StationInfo[idx][sProduits],StationInfo[idx][sMaxProduits],(StationInfo[idx][sMaxProduits]-StationInfo[idx][sProduits]));
      
Create3DTextLabel(string,COLOR_ADMIN,StationInfo[idx][sPosX],StationInfo[idx][sPosY],StationInfo[idx][sPosZ],40.0,01);

    printf("ID: %d | Nom: %s | Produits: %d/%d | Caisse: %d\n",
    idx,
    StationInfo[idx][sName],
    StationInfo[idx][sProduits],
    StationInfo[idx][sMaxProduits],
    StationInfo[idx][sCaisse]);
                        
idx++;
                }
                
fclose(file);
         }
        return 
1;
}


forward SaveStation();
public 
SaveStation()
{
    new 
idx;
new Filefile2;
while (idx sizeof(StationInfo))
{
        new 
coordsstring[512];
    format(coordsstringsizeof(coordsstring), "%s|%f|%f|%f|%f|%f|%f|%d|%d|%d\n",
StationInfo[idx][sName],
StationInfo[idx][sPosX],
    StationInfo[idx][sPosY],
    StationInfo[idx][sPosZ],
    StationInfo[idx][sLivX],
    StationInfo[idx][sLivY],
    StationInfo[idx][sLivZ],
    StationInfo[idx][sProduits],
    StationInfo[idx][sMaxProduits],
    StationInfo[idx][sCaisse]);
    if(idx == 0)
{
file2 fopen("station.txt"io_write);
}
else
{
file2 fopen("station.txt"io_append);
}
fwrite(file2coordsstring);
idx++;
fclose(file2);
}
return 1;
}

?>



Voila, si vous aviez une petite idée pour me permettre de résoudre ce problème je vous en serait reconnaissant !

Vincent.

Hors ligne Ssk

  • *
  • Lulu's Stunt - Le serveur stunt de Lulu !
  • Messages: 8154
    • Voir le profil
Re : Problème de lecture de fichier
« Réponse #1 le: 05 Novembre 2010, 08:06:13 »
Je ne connais pas du tout le fonctionnement de la fonction split, mais je pense qu'elle fonctionne à peu près comme les fonctions strtok, quand tu écris dans le fichier tu ne met pas tout les "|" qu'il faut pour que la fonction puisse récupérer toute les infos.


Toi tu fais ça:

format(coordsstring, sizeof(coordsstring), "%s|%f|%f|%f|%f|%f|%f|%d|%d|%d\n"
alors qu'il faut faire ça:

format(coordsstring, sizeof(coordsstring), "%s|%f|%f|%f|%f|%f|%f|%d|%d|%d|\n"

Il faut tester car je ne suis pas du tout sur et certain.



Derrière tout programme se cache un programmeur, je considère le monde comme un programme.
Mon blog

Hors ligne vardanega

  • *
  • Tueur en série
  • http://vvardanega.wordpress.com (mon blogue)
  • Messages: 155
    • Voir le profil
Re : Problème de lecture de fichier
« Réponse #2 le: 05 Novembre 2010, 08:52:03 »
Heu non voila comment cela ce passe avant et apres la sauvegarde du fichier:

<?php

[08:53:20IDNomStation 1 Produits250/500 Caisse1

[08:53:20IDNomStation 2 Produits250/500 Caisse2

[08:53:20IDNomStation 3 Produits250/500 Caisse3

[08:53:20IDNomStation 4 Produits250/500 Caisse4

[08:53:20IDNomStation 5 Produits250/500 Caisse5

[08:53:20IDNomStation 6 Produits250/500 Caisse6

[08:53:20IDNomStation 7 Produits250/500 Caisse7

[08:53:20IDNomStation 8 Produits250/500 Caisse8

[08:53:20IDNomStation 9 Produits59685/1000000 Caisse99


----------
Loaded log file"server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3b R2, (C)2005-2010 SA-MP Team

[08:54:44] [MySQLConnected (0to root localhost via TCP/IP.
[
08:54:44] [MySQLVersion 5.1.36-community-log.

[
08:54:44IDNomStation 9 Produits59800/1000000 Caisse99

[08:54:44IDNom:  | Produits59800/1000000 Caisse99

[08:54:44IDNomStation 3 Produits250/500 Caisse3

[08:54:44IDNomStation 4 Produits250/500 Caisse4

[08:54:44IDNomStation 5 Produits250/500 Caisse5

[08:54:44IDNomStation 6 Produits250/500 Caisse6

[08:54:44IDNomStation 7 Produits250/500 Caisse7

[08:54:44IDNomStation 8 Produits250/500 Caisse8

[08:54:44IDNomStation 9 Produits59685/1000000 Caisse99


?>


Si vous aviez une solution ! merci.

Vincent
« Modifié: 05 Novembre 2010, 08:57:50 par vardanega »

Hors ligne vardanega

  • *
  • Tueur en série
  • http://vvardanega.wordpress.com (mon blogue)
  • Messages: 155
    • Voir le profil
Re : Problème de lecture de fichier
« Réponse #3 le: 06 Novembre 2010, 09:56:56 »
Up

Aucune idée ?

Hors ligne Ssk

  • *
  • Lulu's Stunt - Le serveur stunt de Lulu !
  • Messages: 8154
    • Voir le profil
Re : Problème de lecture de fichier
« Réponse #4 le: 06 Novembre 2010, 11:31:54 »
Bizarre je ne comprend pas trop problème ^^


Avant la sauvegarde met des printf pour voir ce que contient la variable coordsstring



Derrière tout programme se cache un programmeur, je considère le monde comme un programme.
Mon blog

Hors ligne vardanega

  • *
  • Tueur en série
  • http://vvardanega.wordpress.com (mon blogue)
  • Messages: 155
    • Voir le profil
Re : Problème de lecture de fichier
« Réponse #5 le: 06 Novembre 2010, 11:59:11 »
Bonjour, tout d'abord merci pour votre aide !

Voici le contenue du printf de la sauvegarde:


<?php
[11:52:17CONTENUE DU SAVESTATIONStation 9|272.839996|1348.430053|10.590000|264.750000|1375.459960|10.590000|59800|1000000|99
[11:52:17CONTENUE DU SAVESTATION2|2203.560058|2495.040039|10.819999|250.000000|500.000000|2.000000|59800|1000000|99
[11:52:17CONTENUE DU SAVESTATIONStation 3|2147.179931|2748.699951|10.819998|2112.080078|2741.449951|10.819998|250|500|3
[11:52:17CONTENUE DU SAVESTATIONStation 4|1595.010009|2199.129882|10.819999|1610.189941|2230.979980|10.819999|250|500|4
[11:52:17CONTENUE DU SAVESTATIONStation 5|2640.280029|1106.599975|10.819999|2624.610107|1130.920043|10.819999|250|500|5
[11:52:17CONTENUE DU SAVESTATIONStation 6|610.049987|1689.819946|7.190000|638.190002|1684.359985|6.989999|250|500|6
[11:52:17CONTENUE DU SAVESTATIONStation 7|-1470.979980|1864.069946|32.630001|-1492.020019|1873.130004|32.630001|250|500|7
[11:52:17CONTENUE DU SAVESTATIONStation 8|-1327.640014|2677.350097|50.060001|-1323.229980|2690.070068|50.060001|250|500|8
[11:52:17CONTENUE DU SAVESTATIONStation 9|272.839996|1348.430053|10.590000|264.750000|1375.459960|10.590000|59800|1000000|99


//POURTANT VOICI LE CONTENUE DU LOADSTATION AU DEMARRAGE:

[11:51:43IDNomStation 1 Produits250/500 Caisse1

[11:51:43IDNomStation 2 Produits250/500 Caisse2

[11:51:43IDNomStation 3 Produits250/500 Caisse3

[11:51:43IDNomStation 4 Produits250/500 Caisse4

[11:51:43IDNomStation 5 Produits250/500 Caisse5

[11:51:43IDNomStation 6 Produits250/500 Caisse6

[11:51:43IDNomStation 7 Produits250/500 Caisse7

[11:51:43IDNomStation 8 Produits250/500 Caisse8

[11:51:43IDNomStation 9 Produits59685/1000000 Caisse//station source

?>


Merci !

Vincent



Double post
Tout d'abord désolé du double post,

Je voulais apportez un petit détail dont je vient de m'apercevoir l'existence.

Apparament quand on coupe le serveur c'est a ce moment que le fichier de sauvegarde ce mélange et devient invalide !

Merci

Vincent
« Modifié: 06 Novembre 2010, 19:21:29 par vardanega »