Wrap up Text

F

FUGATO

I need to help in my assignment. I need to wrap a text with the
following indications:
1.If you have reached the end of the line (number of characters on this

line >= 40) AND you have reached the end of the current word, start a
new line and reset the number of characters on the line to 0. The end
of a word will be denoted by one of these: blank space, '\n',
'.', ',' or ';'.

#include <stdio.h>
#include <ctype.h>


main()
{
FILE *fp1,*fp2; //fp1 input file, fp2 output file
char filename[30]; //filename character and x is character
char line[80];
char x;
int count=0; // count the line of the file 1
int j=0; //count of character of file 2


printf("Enter the filename to be scanned: "); // ask the user
scanf("%s", filename);


fp1= fopen(filename, "r"); //open input
file,read-only
fp2= fopen("output.txt", "w"); //open outp file,write-only


while((x=getc(fp1))!=EOF) //get next char from input file,
store
in x
{


if(x=='\n' || x=='*') //count the lines of the file1
count++;


if(x=='\n') //separete
words


putc(' ' ,fp2);


else if(x=='*'){ //new line with an
indentation \t


putc('\t',fp2);


}
else if(x!='*') //delete *
{


j++;


putc(x,fp2); //output file


//Begin the Wrap up text but I have problem here. Help!!!
if((j>=40) && (x==' ' || x==';' || x=='.' ||
x==',' || x=='\n'))


do{
putc('\n',fp2); //start new line
count1++;
j=0;
}while(j!=0);
if(x=='\n')
putc('\n',fp2);
}


}

......................
...................
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Wrap up Text 8
Wrap rev 2. 8
Line/word wrap program. 11
Wrap program revised. 5
error 28
code 34
Can any one help me find out what was the problem in this small 5
Why tthe header is not declared ? 17

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top