int main () { FILE *input = fopen("Onegin.txt", "r"); FILE *output = fopen("Sorted_Onegin.txt","w" ); char* line = NULL; size_t n = 0; // Length of line in bytes int i; size_t* pos; pos = malloc(256*sizeof(size_t)); for (i = 0; i < 256; i++) { *(pos + i) = 0; } while (!feof(input)) { n = 0; n = getline(&line, &n, input)*sizeof(char); printf ("%s%d\n", line,(unsigned char) *line ); fseek(output,pos [(unsigned char)*line],2); fprintf(output, "%s", line); move_pos(pos, *line, n); printf("%d", *(pos + 255)); printf("%s%d\n", line, (unsigned char) *line); free (line); line = NULL; } fclose(input); free(pos); fclose(output); return 0; }
int CyclicBufferSection::write(const char *data, const size_t data_len) { assert(data_len <= capacity_); size_t len_to_end = (buffer_ + capacity_) - pos_; if (len_to_end >= data_len) { memcpy(pos_, data, data_len); } else { memcpy(pos_, data, len_to_end); memcpy(buffer_, data + len_to_end, data_len - len_to_end); } move_pos(data_len); return data_len; }
/* Send the page to the printer. */ static int ml600_print_page( gx_device_printer *pdev, FILE *prn_stream) { int ystep; byte data[2][LINE_SIZE*2]; byte buf[LINE_SIZE*2]; int skip; int current; int c_size; int lnum; int line_size; byte rmask; int i; #define LAST ((current ^ 1) & 1) /* initialize this page */ ystep = page_header(pdev, prn_stream); ystep /= 300; /* clear last sent line buffer */ skip = 0; current = 0; for (i = 0; i < LINE_SIZE*2; i++) data[LAST][i] = 0; /* Send each scan line */ line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev); if (line_size > LINE_SIZE || line_size == 0) return 0; rmask = (byte)(0xff << (-pdev->width & 7)); /* right edge */ for (lnum = 0; lnum < pdev->height; lnum++) { int s; s = gdev_prn_copy_scan_lines(pdev, lnum, data[current], line_size); /* Mask right edge bits */ *(data[current] + line_size - 1) &= rmask; /* blank line ? */ for (i = 0; i < line_size; i++) if (data[current][i] != 0) break; if (i == line_size) { skip = 1; current = LAST; continue; } /* move position, if previous lines are skipped */ if (skip) { move_pos(prn_stream, lnum / ystep, lnum % ystep); skip = 0; } /* create one line data */ c_size = make_line_data(data[current], data[LAST], line_size, buf); /* send one line data */ send_line(buf, c_size, prn_stream); /* swap line buffer */ current = LAST; } /* eject page */ fprintf(prn_stream, "\014"); return 0; }
CyclicBufferSection& CyclicBufferSection::operator-=(long value) { move_pos(-value); return *this; }