static int ppm_getuint(int fd) { int ch; int i; int digitVal; do { ch = ppm_getc(fd); } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); if (ch == PLUGIN_ERROR) return PLUGIN_ERROR; if (ch < '0' || ch > '9') { ppm_error("Junk (%c) in file where an integer should be.", ch); return PLUGIN_ERROR; } i = 0; do { digitVal = ch - '0'; if (i > INT_MAX/10 - digitVal) { ppm_error("ASCII decimal integer in file is "\ "too large to be processed."); return PLUGIN_ERROR; } i = i * 10 + digitVal; ch = ppm_getc(fd); } while (ch >= '0' && ch <= '9'); if (ch == PLUGIN_ERROR) return PLUGIN_ERROR; return i; }
/* Get integer */ int ppm_getint(FILE* file){ register char ch; register int i; do{ ch=ppm_getc(file); } while(ch==' ' || ch=='\t' || ch=='\n' || ch=='\r'); if(ch<'0' || ch>'9'){ fprintf(stderr,"Expected a number.\n"); exit(1); } i=0; do{ i=i*10+ch-'0'; ch=ppm_getc(file); } while(ch>='0' && ch<='9'); return i; }
int ppm_getint(FILE *file) { char c; int i = 0; do { c = ppm_getc(file); } while (c==' ' || c=='\t' || c=='\n' || c=='\r'); do { i = i*10 + c-'0'; c = ppm_getc(file); } while (c>='0' && c<='9'); return i; }