home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 1 / FishNMoreVol1.bin / more / code_examples / librar / fasc2lng.c < prev    next >
Text File  |  1989-02-08  |  1KB  |  45 lines

  1. /*--------------------------------------*/
  2. /*                    */
  3. /*            FASC2LNG(X,X)        */
  4. /*                    */
  5. /* Converts bytes from a file to a long */
  6. /* integer. The first argument is the     */
  7. /* file descriptor. The second argument */
  8. /* is the number of bytes to read.      */
  9. /*                    */
  10. /*--------------------------------------*/
  11. # include "stdio.h"
  12. long fasc2lng(fd,a)
  13. int a;
  14. FILE *fd;
  15. {
  16.         int j,e,k,w[10],sign,counter;
  17.         long r,d;
  18.         counter=sign=0;
  19.         for (j=0;j<a;j++){
  20.              e=getc(fd);
  21.              if (!j){
  22.                  if (e==45)
  23.                      sign=1;
  24.                  if (e==45 || e==43)
  25.                      goto A;
  26.              }
  27.              w[counter]=e;
  28.              counter++;
  29.  
  30. A:           ;
  31.         }
  32.         r=0L;
  33.         for (j=0;j<counter;j++){
  34.              d=1L;
  35.              for (k=0;k<a-j-1;k++)
  36.                   d*=10;
  37.              if (w[j]==32)
  38.                  w[j]=48;
  39.              r+=d*(w[j]-48);
  40.         }
  41.         if (sign==1)
  42.             r*=-1;
  43.         return(r);
  44. }
  45.