/** * Reads from a stream one integer-representing string per line, * and writes the corresponding integer to STDOUT. * * @param fd The file handle. */ void process_fd(FILE *fd) { char buf[CL_MAX_LINE_LENGTH]; int i; while(fgets(buf, CL_MAX_LINE_LENGTH, fd)) { i = htonl(atoi(buf)); if (little_endian) i = cl_bswap32(i); /* explicit conversion */ fwrite(&i, 4, 1, NULL); /* always write 4 bytes ! */ } }
/** * Reads one integer at a time from a stream and prints a decimal representation * of it on STDOUT; strings representing ints are split by newlines. * * @param fd The file handle. */ void process_fd(FILE *fd) { int N, k, i; do { /* currently only works on systems with 32bit ints. should really be fixed some time */ N = fread(&buf[0], sizeof(int), CL_MAX_LINE_LENGTH, fd); for ( k = 0; k < N; k++) { i = ntohl(buf[k]); /* convert from CWB to internal format */ if (little_endian) i = cl_bswap32(i); /* explicit conversion */ Rprintf( "%d\n", i); } } while (N == CL_MAX_LINE_LENGTH); }