Y'a moyen de faire mieux, mais ca marche, donc voilà mon code :
code: with text_io; use text_io; with ada.integer_Text_Io; use ada.integer_Text_Io; with ada.Float_Text_Io; use ada.Float_Text_Io; with sequential_io; procedure DimImage is --////////////////////////////////////////////////////////////////////////-- -- Paquetages -- --////////////////////////////////////////////////////////////////////////-- package fichier_car is new sequential_IO(character); use fichier_car; --////////////////////////////////////////////////////////////////////////-- -- Types -- --////////////////////////////////////////////////////////////////////////-- -- Type qui contient la chaine décrivant les dimensions de l'image type TabDim is array(1..10) of character; --////////////////////////////////////////////////////////////////////////-- -- Fonctions -- --////////////////////////////////////////////////////////////////////////-- function CarVersNombre(Car : in character; Rang : integer) return integer is Resultat : integer; Coeff : integer:= 1; begin case Car is when '0' => Resultat := 0; when '1' => Resultat := 1; when '2' => Resultat := 2; when '3' => Resultat := 3; when '4' => Resultat := 4; when '5' => Resultat := 5; when '6' => Resultat := 6; when '7' => Resultat := 7; when '8' => Resultat := 8; when '9' => Resultat := 9; when others => Resultat := 0; end case; if Rang = 0 then Coeff := 1; else for i in 0..(Rang - 1) loop Coeff := (Coeff * 10); end loop; end if; Resultat := Resultat * Coeff; return Resultat; end CarVersNombre; --////////////////////////////////////////////////////////////////////////-- -- Procédures -- --////////////////////////////////////////////////////////////////////////-- -- Procédure qui va lire les dimensions d'une imageet les mettre dans DimL, et DimH procedure LireDimImage(Fichier : in fichier_car.file_type; DimL, DimH : in out integer) is ComptChar10 : integer := 0; CarLu : character; i : integer := 1; Tab : TabDim := ('a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'); rang : integer := 0; EspaceTrouve : boolean := false; begin DimL := 0; DimH := 0; while ComptChar10 < 3 loop read(Fichier, Carlu); if ComptChar10 = 2 then Tab(i) := CarLu; i := i + 1; end if; if Carlu = character'val(10) then ComptChar10 := ComptChar10 + 1; end if; end loop; for i in reverse 1..10 loop if Tab(i) /= 'a' then if Tab(i) = ' ' then EspaceTrouve := true; Rang := 0; end if; if Tab(i) /= 'a' then Rang := Rang + 1; if EspaceTrouve = true then DimH := DimH + CarVersNombre(Tab(i), rang - 2); else DimL := DimL + CarVersNombre(Tab(i), rang - 2); end if; end if; end if; end loop; end LireDimImage; --////////////////////////////////////////////////////////////////////////-- -- Prog Principal -- --////////////////////////////////////////////////////////////////////////-- NomFichierInitial : string(1..30); comptChaine : integer; fichierInitial : fichier_car.file_type; DimL, DimH : integer; begin put("Donnez le nom du fichier a etudier : "); get_line(item => nomFichierInitial, last => comptChaine); open(fichierInitial, in_file, nomFichierInitial(1..comptChaine)); LireDimImage(FichierInitial, DimL, DimH); put("Largeur : "); put(DimL); new_Line; put("Hauteur : "); put(DimH); end DimImage; |