Page 394 - Programming Microcontrollers in C
P. 394

The printout() and the printafter() Functions   379

                   {
                       char na[ALEN],nu[NLEN];
                       int i,j,k,count=0;

                       if(LIST_ENTRIES==0)
                        return;              /* no entries */
                       k=START_OF_LIST;
                       do
                       {
                          i=epro->header[k].dataindex;
                          j=decode(&epro->data[i],na);
                          puts(na);
                          putbcd(&epro->data[i+j+1],nu);
                          puts(nu);
                          k=epro->header[k].next;
                          count++;
                       }
                       while(count<LIST_ENTRIES && count<DLEN);
                   }

                              Listing 7-14: The printout() Function
                              Listing 7-15 contains the printafter() routine. Here, the
                          routine cycles through the data, decodes it and prints it out one Entry
                          at a time. In this case, the parameter k is static and it starts with the
                          value 0. This is the value of the index to the first Entry in the array.
                          After each output, k is incremented and so is count. Whenever
                          count attains the value LIST_ENTRIES, all of the data in the
                          memory has been printed out. Then count is restored to 0 along
                          with the value of k being set to 0. This action causes the data in the
                          array to be printed out one field at a time and when all of the data are
                          sent out, it is restored to the beginning of the array and recycled.

                   #include “phone.h”

                   void printafter(Epro *epro)
                   {
                       char na[ALEN],nu[NLEN];
                       int j,i;
                       static k=0,count=0;
   389   390   391   392   393   394   395   396   397   398   399