image.c: use MAX
This commit is contained in:
parent
aec66da3b1
commit
556189ee3a
10
src/image.c
10
src/image.c
|
@ -1,5 +1,12 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/param.h> // MAX
|
||||||
|
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
|
||||||
|
#define LINELEN 20000
|
||||||
|
|
||||||
char *readImage(const char* filename, int *cols, int *rows) {
|
char *readImage(const char* filename, int *cols, int *rows) {
|
||||||
|
|
||||||
FILE *f = fopen(filename, "r");
|
FILE *f = fopen(filename, "r");
|
||||||
|
@ -11,7 +18,7 @@ char *readImage(const char* filename, int *cols, int *rows) {
|
||||||
if (!f) {
|
if (!f) {
|
||||||
while (fgets(linebuf, LINELEN, f)) {
|
while (fgets(linebuf, LINELEN, f)) {
|
||||||
int len = strlen(linebuf);
|
int len = strlen(linebuf);
|
||||||
*cols = len>*cols?len:*cols;
|
*cols = MAX(len, *cols);
|
||||||
(*rows)++;
|
(*rows)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,3 +36,4 @@ char *readImage(const char* filename, int *cols, int *rows) {
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
#ifndef __IMAGE
|
#ifndef __IMAGE
|
||||||
#define __IMAGE
|
#define __IMAGE
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define LINELEN 20000
|
|
||||||
|
|
||||||
char *readImage(const char* filename, int *cols, int *rows);
|
char *readImage(const char* filename, int *cols, int *rows);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user