* range in ascii
@ 2005-03-22 15:26 mieville
2005-03-22 15:43 ` Peter Hermann
2005-03-22 17:32 ` Martin Dowie
0 siblings, 2 replies; 7+ messages in thread
From: mieville @ 2005-03-22 15:26 UTC (permalink / raw)
Hi all, thanks for the message regarding packages, indeed this was the
problem.
Now I have another questions, I am reading from ada a .txt file and
counting the letters/word. But counting the letters I have declared my
subtype letters is Character range 'a' .. 'z', but I also want to count
upper case letters and other ASCII char. How should I declare my range
of char.
Thanks for this help and apologies if my questions seems simple, easy
or obvious but I am starting w/ada.
Best, Sib
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: range in ascii
2005-03-22 15:26 range in ascii mieville
@ 2005-03-22 15:43 ` Peter Hermann
2005-03-31 9:37 ` mieville
2005-03-22 17:32 ` Martin Dowie
1 sibling, 1 reply; 7+ messages in thread
From: Peter Hermann @ 2005-03-22 15:43 UTC (permalink / raw)
mieville@mac.com wrote:
> counting the letters/word. But counting the letters I have declared my
kount : array(character) of natural := (others => 0);
mmmh? ;-)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: range in ascii
2005-03-22 15:26 range in ascii mieville
2005-03-22 15:43 ` Peter Hermann
@ 2005-03-22 17:32 ` Martin Dowie
1 sibling, 0 replies; 7+ messages in thread
From: Martin Dowie @ 2005-03-22 17:32 UTC (permalink / raw)
mieville@mac.com wrote:
> Hi all, thanks for the message regarding packages, indeed this was the
> problem.
> Now I have another questions, I am reading from ada a .txt file and
> counting the letters/word. But counting the letters I have declared my
> subtype letters is Character range 'a' .. 'z', but I also want to count
> upper case letters and other ASCII char. How should I declare my range
> of char.
> Thanks for this help and apologies if my questions seems simple, easy
> or obvious but I am starting w/ada.
So read a 'Character' and then decide what it is.
Cheers
-- Martin
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: range in ascii
2005-03-22 15:43 ` Peter Hermann
@ 2005-03-31 9:37 ` mieville
2005-03-31 10:52 ` Anders Wirzenius
2005-03-31 19:15 ` Jeffrey Carter
0 siblings, 2 replies; 7+ messages in thread
From: mieville @ 2005-03-31 9:37 UTC (permalink / raw)
Hi all, I now have my code to count frequency of letters in a text but
I do not know how to read the command "enter" after I write my text.
What I have now is CTRL+Q but of course is not an elegant solution and
I know there is something easy but I cannot find it. Here below is my
code if someone could help me in that single question I would be
grateful. many thanks - sibyl
with Text_Io;
use Text_Io;
with Ada.Integer_Text_Io;
use Ada.Integer_Text_Io;
procedure Comptelettretest is
Char , char2 : Character;
cod: integer ;
subtype Lettre is Integer range 20..255;
type Freq_Lettre is array (Lettre) of Integer;
Count : Freq_Lettre:= (others => 0);
begin
Put_Line ("Entrer un text au choix et le terminer par 'CTRL/Q' et
'enter' ");
loop
Get(Char);
--how to escape from this instruction, I want to hit enter and
have the list.
exit when Char = ASCII.DC1;
cod := CHARACTER'POS(CHAR);
if cod in Lettre then
Count(cod) := Count (cod) +1;
end if;
end loop;
New_Line;
Put_Line("Frequence des lettres");
New_Line;
for cod in Lettre loop
char2 := CHARACTER'VAL(cod);
Put(char2);
put(Count(cod));
New_Line;
end loop;
end Comptelettretest;
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: range in ascii
2005-03-31 9:37 ` mieville
@ 2005-03-31 10:52 ` Anders Wirzenius
2005-03-31 11:23 ` Alex R. Mosteo
2005-03-31 19:15 ` Jeffrey Carter
1 sibling, 1 reply; 7+ messages in thread
From: Anders Wirzenius @ 2005-03-31 10:52 UTC (permalink / raw)
mieville@mac.com writes:
> Hi all, I now have my code to count frequency of letters in a text but
> I do not know how to read the command "enter" after I write my text.
> What I have now is CTRL+Q but of course is not an elegant solution and
> I know there is something easy but I cannot find it. Here below is my
> code if someone could help me in that single question I would be
> grateful. many thanks - sibyl
>
> with Text_Io;
> use Text_Io;
>
> with Ada.Integer_Text_Io;
> use Ada.Integer_Text_Io;
>
> procedure Comptelettretest is
>
> Char , char2 : Character;
> cod: integer ;
> subtype Lettre is Integer range 20..255;
> type Freq_Lettre is array (Lettre) of Integer;
> Count : Freq_Lettre:= (others => 0);
>
> begin
>
> Put_Line ("Entrer un text au choix et le terminer par 'CTRL/Q' et
> 'enter' ");
> loop
Get_Immediate (Char);
Put (Char);
-- Get (Char)
> Get(Char);
>
> --how to escape from this instruction, I want to hit enter and
> have the list.
exit when Char = ASCII.CR; -- Works at least on Windows
> exit when Char = ASCII.DC1;
> cod := CHARACTER'POS(CHAR);
> if cod in Lettre then
> Count(cod) := Count (cod) +1;
> end if;
> end loop;
>
> New_Line;
> Put_Line("Frequence des lettres");
> New_Line;
> for cod in Lettre loop
> char2 := CHARACTER'VAL(cod);
> Put(char2);
> put(Count(cod));
> New_Line;
> end loop;
>
> end Comptelettretest;
Anders
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: range in ascii
2005-03-31 10:52 ` Anders Wirzenius
@ 2005-03-31 11:23 ` Alex R. Mosteo
0 siblings, 0 replies; 7+ messages in thread
From: Alex R. Mosteo @ 2005-03-31 11:23 UTC (permalink / raw)
Anders Wirzenius wrote:
> mieville@mac.com writes:
>
>
>>Hi all, I now have my code to count frequency of letters in a text but
>>I do not know how to read the command "enter" after I write my text.
>>What I have now is CTRL+Q but of course is not an elegant solution and
>>I know there is something easy but I cannot find it. Here below is my
>>code if someone could help me in that single question I would be
>>grateful. many thanks - sibyl
>>
>>with Text_Io;
>>use Text_Io;
>>
>>with Ada.Integer_Text_Io;
>>use Ada.Integer_Text_Io;
>>
>>procedure Comptelettretest is
>>
>> Char , char2 : Character;
>> cod: integer ;
>> subtype Lettre is Integer range 20..255;
>> type Freq_Lettre is array (Lettre) of Integer;
>> Count : Freq_Lettre:= (others => 0);
>>
>>begin
>>
>> Put_Line ("Entrer un text au choix et le terminer par 'CTRL/Q' et
>>'enter' ");
>> loop
>
>
> Get_Immediate (Char);
> Put (Char);
> -- Get (Char)
Mmmmm, what about the old Get_Line? Isn't it just the thing to use for
enter-finished inputs?
You'll get a string instead of a character, but iterating over its
characters is just as easy.
>
>
>> Get(Char);
>>
>> --how to escape from this instruction, I want to hit enter and
>>have the list.
>
>
> exit when Char = ASCII.CR; -- Works at least on Windows
>
>
>
>> exit when Char = ASCII.DC1;
>> cod := CHARACTER'POS(CHAR);
>> if cod in Lettre then
>> Count(cod) := Count (cod) +1;
>> end if;
>> end loop;
>>
>>New_Line;
>> Put_Line("Frequence des lettres");
>> New_Line;
>> for cod in Lettre loop
>> char2 := CHARACTER'VAL(cod);
>> Put(char2);
>> put(Count(cod));
>> New_Line;
>> end loop;
>>
>>end Comptelettretest;
>
>
> Anders
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: range in ascii
2005-03-31 9:37 ` mieville
2005-03-31 10:52 ` Anders Wirzenius
@ 2005-03-31 19:15 ` Jeffrey Carter
1 sibling, 0 replies; 7+ messages in thread
From: Jeffrey Carter @ 2005-03-31 19:15 UTC (permalink / raw)
mieville@mac.com wrote:
> type Freq_Lettre is array (Lettre) of Integer;
Integer allows negative values, so I guess negative frequencies are
meaningful? If not, perhaps you should use Natural.
Why not use
subtype Lettre is Character range 'x' ... 'z'; -- or whatever
and avoid the conversions between Characters and Integers?
> Put_Line ("Entrer un text au choix et le terminer par 'CTRL/Q' et
> 'enter' ");
Read_Input : declare
Line : constant String := PragmARC.Get_Line;
begin
All_Chars : for I in Line'range loop
if Line (I) in Lettre then
Count (Line (I) ) := Count (Line (I) ) + 1;
end if;
end loop All_Chars;
end Read_Input;
The PragmAda Reusable Components are available from
http://home.earthlink.net/~jrcarter010/pragmarc.htm
--
Jeff Carter
"I unclog my nose towards you."
Monty Python & the Holy Grail
11
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-03-31 19:15 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-22 15:26 range in ascii mieville
2005-03-22 15:43 ` Peter Hermann
2005-03-31 9:37 ` mieville
2005-03-31 10:52 ` Anders Wirzenius
2005-03-31 11:23 ` Alex R. Mosteo
2005-03-31 19:15 ` Jeffrey Carter
2005-03-22 17:32 ` Martin Dowie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox