From: invalid@invalid.invalid   
      
    schrieb im Newsbeitrag   
   news:1139701168.899067.215210@g47g2000cwa.googlegroups.com...   
   > Hi, consider the following code:   
   > --   
   > program sample1;   
   > var   
   > x : integer;   
   > y : char;   
   > begin   
   > readln(x,y);   
   > writeln(x,' ',y);   
   > end.   
   > --   
   > If i run it and i type something like this:   
   > 5 a   
   > I only get printed: 5 but not a (the caracter variable is always 'in   
   > blank' regardless of the character i typed)   
      
   I guess you need to type 5a without a whitespace.   
   You could declare y as string.   
   But then you get all following characters as typed in.   
      
   >   
   > But consider this other sample:   
   > --   
   > program sample2;   
   > var   
   > x : integer;   
   > y : integer; (*integer instead of char, the rest is all the same*)   
   > begin   
   > readln(x,y);   
   > writeln(x,' ',y);   
   > end.   
   > --   
   > Now if i run the program and i type:   
   > 5 3   
   > Then i get 5 3 printed.   
   >   
   > So, why isn't the first code behaving the way i think it should?? Why   
   > don't it store the character in the char variable??   
      
   reading a number skips leading whitespaces, but not trailing.   
      
   > Thanks in advance   
   >   
      
   If you want to input something like   
   1 a 2   
   into integer, char, integer, then you should read the whole line   
   into a string s and parse on your own.   
      
   val(s, x, ErrorPos);   
   if ErrorPos = 1 then   
    ErrorMessage;   
   s := Copy(s, ErrorPos, length(s));   
   while s[1] = ' ' do   
    s := Copy(s, 2, length(s));   
   y := s[1];   
   s := Copy(s, 2, length(s));   
   val(s, z, ErrorPos);   
   if ErrorPos = 1 then   
    ErrorMessage;   
   if Copy(s, ErrorPos, length(s)) > '' then   
    ExtraInputMessage;   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|