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);
}
}
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);
}
}