p8: fixed issue with p8 not following ANSI C standard
This commit is contained in:
parent
1c210b879d
commit
5e39e3554e
5 changed files with 73 additions and 25 deletions
24
lib/io.c
Normal file
24
lib/io.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
#include "io.h"
|
||||
|
||||
int readnum(FILE *fd, char *buf, size_t len) {
|
||||
|
||||
int i = 0;
|
||||
|
||||
for(;;) {
|
||||
int c = getc(fd);
|
||||
|
||||
if (c == EOF)
|
||||
break;
|
||||
if (c < '0' || c > '9')
|
||||
continue;
|
||||
|
||||
buf[i] = c;
|
||||
|
||||
if (i+1 > len)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
9
lib/io.h
Normal file
9
lib/io.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#ifndef __IO_H
|
||||
#define __IO_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int readnum(FILE *fd, char *buf, size_t len);
|
||||
|
||||
#endif /* __IO_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue