simple word wrap problem not wrapping

From: Douglas G (dgardiner_at_houston.rr.com)
Date: 08/31/04


Date: Tue, 31 Aug 2004 05:33:35 GMT

I've tried various ideas on this problem, but I don't see word wrapping.

Can you point out what is wrong? It's a K&R exercise, and I'm still new to
programming. Other pointers would be helpful too.

#include "header.h"
/* does the wordwrapping */

void fold(char buffer[], int len)
{
  int start_point,i;
  
  start_point=i=0;
  while (len > (start_point +COLUMN)) {
    i=start_point+COLUMN;
    while ( buffer[i]!=' ' || buffer[i]!='\t')
      start_point=--i;
    buffer[++i]='\n';
  }
  start_point=i=0;
  
  return;
}

[snippet from header.h]

/* header.h */
#include <stdio.h>
#define MAXLINE 1000 /* maximum input line size */
#define COLUMN 35 /* length before fold */



Relevant Pages

  • Re: a round of asm golf (searching for sequence of bytes)
    ... I'm working on a small exercise to size optimize a little search ... I have a search for a 2 byte sequence down to 12 bytes. ... esi = points to first byte in our buffer ...
    (comp.lang.asm.x86)
  • Re: Why does this work? POSTPONE [Beginner]
    ... You may use a temporary compilation buffer. ... Forth, I will leave the implementation as an exercise, but provide use ... IMMEDIATE ...
    (comp.lang.forth)
  • Help with "read" issue please
    ... I am working on a simple exercise for school that is supposed to use read to ... I am supposed to change the buffer size and see ... dump - segmentation fault. ...
    (comp.lang.cpp)
  • Re: calloc and hash tables
    ... That's a bug. ... snippet that exhibits the problem. ... exercise is not just a usenet courtesy, ...
    (comp.lang.c)
  • realloc question
    ... Just an exercise: ... Let's assume it worked well and we have 1000 bytes in Buffer. ... Let's pretend it failed. ... ReallocatedBuffer = NULL by definition, ...
    (microsoft.public.vc.language)