[comp.lang.pascal] uppercase and char and string[1];

cs211s65@uhccux.uhcc.hawaii.edu (Cs211s65) (11/17/89)

Aloha Networld,
  First I would like to thank all of you who responded to my question
about how to get a run on to the printer. Sorry about the flamefest I
created. 
 My problem, or more like question: Since my pascal teacher here in 
Hawaii has a thing against turbo Pascal, she doesnt allow, or takes off
points if one uses non-standard commands, So.. when I declare a string,
I have to declare it as type packed array [1..10] of char. My question  
is, how would I change a string of that type to an all upper case string,
the way she instructed us to do it is by writing it to a file, and reading
it character by character so that you can get an upper case by the 
formula chr(character+(ord('a') - ord('A')) (something like that) but 
I KNOW there has to be an easier way (in standard pascal) any help would
be appreciated. 
 Secondly, Despite my teacher's dislike of Turbo Pascal, I broke down and
used a STRING[1] type, BUT, when I try to use ord or chr functions it
gave me a TYPE MISMATCH error, so I wanted to make it into a char character.
so I char_letter := string_letter; but the compiler would now accept it.
How do I make a single length STRING[1] type character to a CHAR character?
Please help..  
					ALoha and Mahalo from Sunny Hawaii!
					edward Yagi AKA edman!

ps. conoutptr := lstoutptr  works the best!
 t h a n k  y o u  v e r y  m u c h ! ! ! 

mikej@vax1.acs.udel.EDU (Michael Jacobs) (11/17/89)

>I have to declare it as type packed array [1..10] of char. My question  
>is, how would I change a string of that type to an all upper case string,
>the way she instructed us to do it is by writing it to a file, and reading
>it character by character so that you can get an upper case by the 
>formula chr(character+(ord('a') - ord('A')) (something like that) but 
>I KNOW there has to be an easier way (in standard pascal) any help would
>be appreciated. 
> Secondly, Despite my teacher's dislike of Turbo Pascal, I broke down and
>used a STRING[1] type, BUT, when I try to use ord or chr functions it
>gave me a TYPE MISMATCH error, so I wanted to make it into a char character.
>so I char_letter := string_letter; but the compiler would now accept it.
>How do I make a single length STRING[1] type character to a CHAR character?

As you may know, when you declare a variable to be, say, STRING[10], you
are in reality saying ARRAY [0..10] OF CHAR, where the 0th element
holds the length, and the rest the actual data.  

I don't know if UPCASE is a standard function; if it isn't, define it:
FUNCTION UPCASE ( A : CHAR ) : CHAR;
BEGIN
IF A IN ['a'..'z'] THEN UPCASE = CHR ( ORD(A) - ORD('A') ) ELSE UPCASE := A
END;

VAR X : STRING[10]; { or ARRAY[0..10] OF CHAR }

to capitalize it, 

IF ORD( X[0] ) > 0 THEN
  FOR I := 1 to ORD( X[0] ) DO
	X[I] := UPCASE ( X[I] );


So, when you're referring to something defined as STRING[1], it's not the
same as a char, it an array of 2 chars.  each element is a char.


-- 

Mike J             |  
The Grey Sysop...  |  Phone...RING!...yep yep yep yep yep!
                   |  

reino@cs.eur.nl (Reino de Boer) (11/17/89)

cs211s65@uhccux.uhcc.hawaii.edu (Cs211s65) writes:

>Aloha Networld, .......
>....... So.. when I declare a string,
>I have to declare it as type packed array [1..10] of char. My question  
>is, how would I change a string of that type to an all upper case string,

How about:

var s : packed array [1..10] of char;
	i : integer;
begin
  ....
  for i := 1 to 10 do
	if( 'a' <= s[i] ) and ( s[i] <= 'z' ) then { convert it }
	  s[i] := chr( ord( s[i] ) - ord( 'a' ) + ord( 'A' ) );
	{ else leave it alone }
  ....
end.
-- 
Reino R. A. de Boer
Erasmus University Rotterdam ( Informatica )
e-mail: reino@cs.eur.nl

TBC101@PSUVM.BITNET (TomShark Collins) (11/18/89)

In article <5477@uhccux.uhcc.hawaii.edu>, cs211s65@uhccux.uhcc.hawaii.edu
(Cs211s65) says:
> Secondly, Despite my teacher's dislike of Turbo Pascal, I broke down and
>used a STRING[1] type, BUT, when I try to use ord or chr functions it
>gave me a TYPE MISMATCH error, so I wanted to make it into a char character.
>so I char_letter := string_letter; but the compiler would now accept it.
>How do I make a single length STRING[1] type character to a CHAR character?
>
The following shows how to assign a string of length 1 to a character:

Program X;
Var       SmallStr :String[1];
          Character:Char;
Begin
    ...
    Character := SmallStr[1];
    ...
End.

-------
Tom "Shark" Collins       Since ICS is comprised of 2 people, my views
tbc101@psuvm.psu.edu      are the opinion of at least 50% of the company.

dsrekml@prism.gatech.EDU (Mike Mitten) (11/27/89)

In article <5477@uhccux.uhcc.hawaii.edu>, cs211s65@uhccux.uhcc.hawaii.edu
(Cs211s65) says:
> Secondly, Despite my teacher's dislike of Turbo Pascal, I broke down and
>used a STRING[1] type, BUT, when I try to use ord or chr functions it
>gave me a TYPE MISMATCH error . . .

	If you were doing ord(String1Var) you were getting the type mismatch
because you are passing a string variable to a function which needs a char
variable.  This should be avoidable by using ord(String1Var[1]).

	Hope this helps,

	-Mike

Mike  Mitten                              -- Irony is the spice of life. --
WREK Radio, Georgia Tech, Atlanta GA, 30332  (404) 894-2468
ARPA:  dsrekml@prism.gatech.edu
uucp: ...!{allegra,amd,hplabs,seismo,ut-ngp}!gatech!prism!dsrekml
| CAUTION:  The above is the output of experimental software simulating the   |
|           result of 1000 monkeys typing on 1000 typewriters for 1000 years. |