The question of the program is written in program comments.
First, the program is creating weird output.
Second, getch() is not holding the console screen. The program terminates without showing output, which I have to check by reexecuting(removed clrscr for that)
Please help me with this!
/*Write a paragraph to a text file data.txt then create a file that stores
text lines along with line numbers. A line can have maximum 75 characters or
ends at '.' whichever occurs earlier*/
#include<fstream.h>
#include<conio.h>
void main()
{
char para[500];
cout<<"\nEnter the paragraph(Enter $to end";
cin.getline(para,500,'$');
for(int i=0;para[i]!='\0';i++);
i--;
ofstream fout("data.txt",ios::out);
fout.write(para,i);
fout.close();
ifstream fin("data.txt",ios::in);
fout.open("text.txt",ios::out);
while(1)
{ int i=1;
fin.getline(para,75,'.');
if(!fin)break;
for(int j=0;para[j]!='\0';j++);
j--; //j indicates size of the line
cout<<"\n"<<i<<". ";
cout.write(para,j);
fout<<"\n"<<i<<". ";
fout.write(para,j);
++i;
}
fout.close();
fin.close();
getch();
}
Your C++ version is way old, pre-standard even. I'd advise an immediate update. Anyhow, I made a few changes, just enough to get it compiling with a standard compiler, and it seems to work fine.
Please note however, that the language has evolved to provide much better ways of doing what you're attempting here.