예제 #1
0
파일: cwb-atoi.c 프로젝트: rforge/rcwb
/**
 * 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 ! */
  }
}
예제 #2
0
파일: cwb-itoa.c 프로젝트: cran/rcqp
/**
 * 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);
}