Monday, November 9, 2009

TEXT LINE LENGTH ADJUSTMENT

TEXT LINE LENGTH ADJUSTMENT

  • AIM

To verify the text line length adjustment

  • PROBLEM DESCRIPTION

In a given set of lines the text length should be re format. So, that the text line of more than n characters that is maximum 40 character should be displayed. The output line maximum number of words that occupy less than or n characters should be printed. No word should extend across two lines. If suppose user give more than 40 characters then infinite loop will occurs.

  • Character length starts with 1.
  • String length function starts with 1.
  • No words in a file should not be splitted.

 

  • EXAMPLE

FLOWERS ARE BEAUT

IFULL.

This is wrong.

FLOWERS ARE BEAUTIFULL.

This is correct.

Flowers-actual is stores from 0-6 (7) elements.

  • ALGORITHM DESCRIPTION
  1. Read the line length limit and add one to it, to allow for a space.
  2. Initialize the word characters counts to 0 and end of line flag to false.
  3. No end of line means, read the next character and store it.
  4. If character is a space or a new paragraph then reset character count for new line.
  5. Add current word length to current line length.
  6. When it across the line length limit then move to next line.
  7. Write out the current word and re-initialize count.
  8. If at end of input line then, set end of input line flag and move to next line.

 

  • IMPLEMENTATION

#include <stdio.h>

#define size 40

Main()

FILE*fp;

Char a[100], str[50], i, empty, length;

Fp=fopen(“sk.txt”,”r”);

While(!feof(fp))

{

Fscanf(fp,”%s”,&a);

Empty=size-strlen(a)-1;

If(empty>length)

{

Strcat(str,a);

Strcat(str,” “);

}

Else

{

Printf(“%s\n”,str);

For(i=0;i<50;i++)

Str[i]=’\0’;

Strcat(str,” “);

}

If(feof(fp))

Printf(“%s\n”,str);

}

Fclose(fp);

Getch();

}

  • APPLICATIONS
  • Text processing,
  • Report writing and
  • File management.

Submitted by

K.KALAISELVI

08BCS033


1 comment:

  1. IT is easier to understand but can you write a programe with out using files.

    ReplyDelete