diff --git a/pointer.adb b/pointer.adb index feb6c76..c96b96e 100644 --- a/pointer.adb +++ b/pointer.adb @@ -150,45 +150,45 @@ procedure pointer is - function saisir2 return list is - liste : list; - ended : boolean := false; - space : boolean := false; - charac : character := ' '; - Num: integer:=0; - val : integer := 0; - s : string(1..1); - I : integer := 0; - aux : list; - first : boolean:= True; + function saisir2 return list is + Llist : list; --returned + ended : boolean := false; --end of first while + space : boolean := false; --end of second + charac : character := ' '; -- to get the char + Num: integer:=0; -- value at the end of the 2nd while + val : integer := 0; -- value from the char used to buid num + s : string(1..1); -- because ada < C and we need to use the Integer'Value on a string as there can be no cast from char to int + I : integer := 0; + aux : list; -- helper + first : boolean:= True; -- to mimick initialization - begin - aux := liste; -- we set the - while (not end_of_line) loop - while (not space and not end_of_line) loop - -- put_line("test"); - get(charac); - if(charac = ' ') then ended := True; space := True; - else - s(1):=charac; - val := integer'Value(s); - -- put_Line("vous avez saisi " & charac); - Num := Num*10+val; - end if; - end loop; - space := False; - if first then - liste := new cell'(Num,Null); - first:= False; - aux := liste; - else - aux.all.next := new cell'(Num, Null); - aux:= aux.all.next; - end if; - Num := 0; - end loop; - return liste; - end saisir2; + begin + aux := Llist; -- we set the helper to list + while (not end_of_line) loop -- check the buffer for upcoming \n + while (not space and not end_of_line) loop -- space is true when char = ' ' + -- put_line("test"); + get(charac); + if(charac = ' ') then ended := True; space := True; + else + s(1):=charac; -- change the char to a string for cast to int + val := integer'Value(s); + put_Line("vous avez saisi " & charac); -- visual confirmation + Num := Num*10+val; -- convert to base 10 value + end if; + end loop; + space := False; -- reset + if first then -- init + Llist := new cell'(Num,Null); + first:= False; + aux := Llist; + else + aux.all.next := new cell'(Num, Null); + aux:= aux.all.next; + end if; + Num := 0; --reset + end loop; + return Llist; + end saisir2; function saisir3 return returned3 is