* Re: Another problems of newbie
2004-12-30 15:31 Another problems of newbie maxsio ;D
@ 2004-12-30 15:30 ` Andre
2004-12-30 18:30 ` Jeffrey Carter
2004-12-31 7:04 ` Martin Krischik
2 siblings, 0 replies; 6+ messages in thread
From: Andre @ 2004-12-30 15:30 UTC (permalink / raw)
maxsio ;D wrote:
> I need to write some program and I have problems with it. This program
> should read text file, write words to array, sort them and than write to
> another text file. In one book I found way how to read only singel char
> so I thought it would be easy to link singel char and rest part of final
> word, but I was wrong. I've written this subprogram (this program is
> reading from keyboard, but with files is similar so...) :
> *
> procedure chars is
> word : string(1..31);
> char : character;
>
> begin
> for i in 1..30 loop
> Get(char);
> word:=word&(string(char));
> end loop;
> Put(word);
> delay 10.0;
> end chars;
> *
> but after first letter program generate constraint error. And second
> problem which I have is sorting array with words. To sort array I've
> choosen QuickSort, but I don't know totally how to use it in Ada. I was
> searching in Google, but I found only QuickSort with pointers.
> Unfortunately I don't understand how to use them good ind this
> algorithm. If anybody could explain usage of pointers in this algorithm
> or write QuickSort without pointers I'd be grateful.
> Sorry for my poor English and thanks in advance. Greetings
>
> maxsio
word:=word&(string(char)) is a concatenation of the string word and the
char. This requiers a sting of 1 .. 32.
what you want is:
word (i) := char;
Andr�
^ permalink raw reply [flat|nested] 6+ messages in thread
* Another problems of newbie
@ 2004-12-30 15:31 maxsio ;D
2004-12-30 15:30 ` Andre
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: maxsio ;D @ 2004-12-30 15:31 UTC (permalink / raw)
I need to write some program and I have problems with it. This program
should read text file, write words to array, sort them and than write to
another text file. In one book I found way how to read only singel char so I
thought it would be easy to link singel char and rest part of final word,
but I was wrong. I've written this subprogram (this program is reading from
keyboard, but with files is similar so...) :
*
procedure chars is
word : string(1..31);
char : character;
begin
for i in 1..30 loop
Get(char);
word:=word&(string(char));
end loop;
Put(word);
delay 10.0;
end chars;
*
but after first letter program generate constraint error. And second problem
which I have is sorting array with words. To sort array I've choosen
QuickSort, but I don't know totally how to use it in Ada. I was searching in
Google, but I found only QuickSort with pointers. Unfortunately I don't
understand how to use them good ind this algorithm. If anybody could explain
usage of pointers in this algorithm or write QuickSort without pointers I'd
be grateful.
Sorry for my poor English and thanks in advance. Greetings
maxsio
--
maxsio@wp.pl
GG: 1447475
IRC: irc.efnet.pl #osiolek
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Another problems of newbie
2004-12-30 15:31 Another problems of newbie maxsio ;D
2004-12-30 15:30 ` Andre
@ 2004-12-30 18:30 ` Jeffrey Carter
2004-12-31 7:04 ` Martin Krischik
2 siblings, 0 replies; 6+ messages in thread
From: Jeffrey Carter @ 2004-12-30 18:30 UTC (permalink / raw)
maxsio ;D wrote:
> procedure chars is
> word : string(1..31);
> char : character;
>
> begin
> for i in 1..30 loop
> Get(char);
> word:=word&(string(char));
> end loop;
> Put(word);
> delay 10.0;
> end chars;
You have some basic misunderstandings. A String is just an array, so to
assign anything to Word, it must be exactly 31 Characters long. Why 31,
when you're only reading 30 Characters? Word (31) is undefined.
Presumably you're doing this to learn Ada. You should work through a
text or tutorial so you understand the basics of the language before
working on anything like this. Then when you have problems they'll be at
a suitable level for asking here. You can find both texts and tutorials
on line at adapower.com and adaworld.com.
When you do get to that level, you'll find that reading words is already
done for you. See PragmARC.Word_Input and the various sorting packages
that are part of the PragmAda Reusable Components. The PragmARCs are
available from
http://home.earthlink.net/~jrcarter010/pragmarc.htm
--
Jeff Carter
"Now look, Col. Batguano, if that really is your name."
Dr. Strangelove
31
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Another problems of newbie
2004-12-30 15:31 Another problems of newbie maxsio ;D
2004-12-30 15:30 ` Andre
2004-12-30 18:30 ` Jeffrey Carter
@ 2004-12-31 7:04 ` Martin Krischik
2004-12-31 13:50 ` Pascal Obry
2 siblings, 1 reply; 6+ messages in thread
From: Martin Krischik @ 2004-12-31 7:04 UTC (permalink / raw)
maxsio ;D wrote:
Just a few hints. After all, you need to learn something.
> I need to write some program and I have problems with it. This program
> should read text file, write words to array, sort them and than write to
> another text file. In one book I found way how to read only singel char so
> I thought it would be easy to link singel char and rest part of final
> word, but I was wrong. I've written this subprogram (this program is
> reading from keyboard, but with files is similar so...) :
> *
> procedure chars is
> word : string(1..31);
I take it you are a C/C++ programmer - otherwise you would not create a
string wich is one char larger then actualy needed.
> char : character;
>
> begin
> for i in 1..30 loop
for i in word'range loop
> Get(char);
> word:=word&(string(char));
Ada "string" is "char []" and "Ada.Strings.Unbounded" is "std::string". And
you would not use operator + () on a char [], would you? So its:
word (i) := char;
> end loop;
> Put(word);
> delay 10.0;
> end chars;
> *
> but after first letter program generate constraint error. And second
> problem which I have is sorting array with words. To sort array I've
> choosen QuickSort, but I don't know totally how to use it in Ada. I was
> searching in Google, but I found only QuickSort with pointers.
> Unfortunately I don't understand how to use them good ind this algorithm.
> If anybody could explain usage of pointers in this algorithm or write
> QuickSort without pointers I'd be grateful.
> Sorry for my poor English and thanks in advance. Greetings
>
> maxsio
> --
> maxsio@wp.pl
> GG: 1447475
> IRC: irc.efnet.pl #osiolek
Free yourself from C/C++ thinking! C/C++ are only mid-level languages and
now you work with a true high level language. Things are diffreren here.
i.E. if you need 30 characters you say 30 and 31 - no need for '\0' here.
Martin
--
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Another problems of newbie
2004-12-31 7:04 ` Martin Krischik
@ 2004-12-31 13:50 ` Pascal Obry
2004-12-31 14:59 ` Martin Krischik
0 siblings, 1 reply; 6+ messages in thread
From: Pascal Obry @ 2004-12-31 13:50 UTC (permalink / raw)
Martin Krischik <martin@krischik.com> writes:
> Free yourself from C/C++ thinking! C/C++ are only mid-level languages and
> now you work with a true high level language. Things are diffreren here.
> i.E. if you need 30 characters you say 30 and 31 - no need for '\0' here.
^^^
I suppose this is what you meant not
Pascal.
--
--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Another problems of newbie
2004-12-31 13:50 ` Pascal Obry
@ 2004-12-31 14:59 ` Martin Krischik
0 siblings, 0 replies; 6+ messages in thread
From: Martin Krischik @ 2004-12-31 14:59 UTC (permalink / raw)
Pascal Obry wrote:
>
> Martin Krischik <martin@krischik.com> writes:
>
>> Free yourself from C/C++ thinking! C/C++ are only mid-level languages and
>> now you work with a true high level language. Things are diffreren here.
>> i.E. if you need 30 characters you say 30 and 31 - no need for '\0' here.
> ^^^
> I suppose this is what you meant not
Yes, of corse it should read: "30 and not 31".
Martin
--
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-12-31 14:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-30 15:31 Another problems of newbie maxsio ;D
2004-12-30 15:30 ` Andre
2004-12-30 18:30 ` Jeffrey Carter
2004-12-31 7:04 ` Martin Krischik
2004-12-31 13:50 ` Pascal Obry
2004-12-31 14:59 ` Martin Krischik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox