home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 1
/
FishNMoreVol1.bin
/
more
/
code_examples
/
librar
/
fasc2lng.c
< prev
next >
Wrap
Text File
|
1989-02-08
|
1KB
|
45 lines
/*--------------------------------------*/
/* */
/* FASC2LNG(X,X) */
/* */
/* Converts bytes from a file to a long */
/* integer. The first argument is the */
/* file descriptor. The second argument */
/* is the number of bytes to read. */
/* */
/*--------------------------------------*/
# include "stdio.h"
long fasc2lng(fd,a)
int a;
FILE *fd;
{
int j,e,k,w[10],sign,counter;
long r,d;
counter=sign=0;
for (j=0;j<a;j++){
e=getc(fd);
if (!j){
if (e==45)
sign=1;
if (e==45 || e==43)
goto A;
}
w[counter]=e;
counter++;
A: ;
}
r=0L;
for (j=0;j<counter;j++){
d=1L;
for (k=0;k<a-j-1;k++)
d*=10;
if (w[j]==32)
w[j]=48;
r+=d*(w[j]-48);
}
if (sign==1)
r*=-1;
return(r);
}