~ubuntu-branches/ubuntu/vivid/inform/vivid

« back to all changes in this revision

Viewing changes to html/answers2/answer96.html

  • Committer: Bazaar Package Importer
  • Author(s): Jan Christoph Nordholz
  • Date: 2008-05-26 22:09:44 UTC
  • mfrom: (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526220944-ba7phz0d1k4vo7wx
Tags: 6.31.1+dfsg-1
* Remove a considerable number of files from the package
  due to unacceptable licensing terms.
* Repair library symlinks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<HTML><HEAD><TITLE>Answer to Exercise 96</TITLE></HEAD>
2
 
<BODY BGCOLOR="#FFFFFF">
3
 
<TABLE><TR><TD Valign="top"><IMG SRC="../icons/exercise.gif" ALT="??"><TD bgcolor="#FAA89B"><B>ANSWER TO EXERCISE 96</B><TR><TD><TD>
4
 
<P>
5
 
 
6
 
The following implementation is limited to a format
7
 
string
8
 
2x64 = 128
9
 
characters long, and six subsequent arguments.
10
 
<TT>%d</TT> becomes a decimal number, <TT>%e</TT> an English one; <TT>%c</TT>
11
 
a character, <TT>%%</TT> a (single) percentage sign and <TT>%s</TT>
12
 
a string.
13
 
<PRE>
14
 
Array printed_text table 64;
15
 
Array printf_vals --&#62; 6;
16
 
[ Printf format p1 p2 p3 p4 p5 p6   pc j k;
17
 
  printf_vals--&#62;0 = p1; printf_vals--&#62;1 = p2; printf_vals--&#62;2 = p3;
18
 
  printf_vals--&#62;3 = p4; printf_vals--&#62;4 = p5; printf_vals--&#62;5 = p6;
19
 
  printed_text--&#62;0 = 64; @output_stream 3 printed_text;
20
 
  print (string) format; @output_stream -3;
21
 
  j=printed_text--&#62;0;
22
 
  for (k=2:k&#60;j+2:k++)
23
 
  {   if (printed_text-&#62;k == '%')
24
 
      {   switch(printed_text-&#62;(++k))
25
 
          {   '%': print "%";
26
 
              'c': print (char) printf_vals--&#62;pc++;
27
 
              'd': print printf_vals--&#62;pc++;
28
 
              'e': print (number) printf_vals--&#62;pc++;
29
 
              's': print (string) printf_vals--&#62;pc++;
30
 
              default: print "&#60;** Unknown printf escape **&#62;";
31
 
          }
32
 
      }
33
 
      else print (char) printed_text-&#62;k;
34
 
  }
35
 
];
36
 
</PRE>
37
 
 
38
 
</TABLE>
39
 
<HR>Back to <A HREF="../section33.html#ex96">the exercise in section 33</A><HR>
40
 
<SMALL><I>Mechanically translated to HTML from third edition as revised 16 May 1997. Copyright &#169; Graham Nelson 1993, 1994, 1995, 1996, 1997: all rights reserved.</I></SMALL></BODY></HTML>