<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0054)http://www.brainmass.com/solution_download.php?id=8063 -->
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2800.1276" name=GENERATOR></HEAD>
<BODY><PRE>#include &lt;iostream.h&gt;
#include &lt;fstream.h&gt;
#include &lt;cstring&gt;
using namespace std;
int MAX = 60;

int main(int argc, char *argv[])
{
	int i=0, j, k, l, n, N;
	char buff[MAX];
    	ifstream fin;  
	fin.open("sometext.txt", ios::in);  
	if (!fin) 
	{ 
		cout &lt;&lt; "Can't open input file. Aborting!\n";
		return 1;
	}
	while(!fin.eof())
	{
	    	fin.getline(buff, MAX);
		i++;
	}
	i--;
	N = i;	
//To check the number of lines in the given file and allocating memory for variables.

	cout &lt;&lt; "Number of lines in the given input file: " &lt;&lt; N &lt;&lt; endl;
	fin.close();

	fin.open("sometext.txt", ios::in);  
	if (!fin) 
	{ 
		cout &lt;&lt; "Can't open input file. Aborting!\n";
		return 1;
	}

	char str[N][MAX], chk_str[MAX], new_str[N][MAX];
	int len_new_str[N];
	i= 0;
	while(!fin.eof())
	{
	    	fin.getline(buff, MAX);
		str[i] = buff;
		cout &lt;&lt; str[i] &lt;&lt; endl;
		i++;
	}
	fin.close();
	i--;
	n = i;
	int margin;
	char ch = 32, ch2 = 9;	//32 == space bar, 9 == tab
	ofstream ofp;
	ofp.open("output.txt");
	if(!ofp)
	{
	    	cerr &lt;&lt; "Unable to open output.txt" &lt;&lt; endl;
		return 1;
	}
	for(i=0;i&lt;n;i++)
	{
	    	chk_str = str[i];
		k = 0;
		for(j=0;j&lt;MAX;j++)
		{
	    		if(chk_str[j] != ch &amp;&amp; chk_str[j] != ch2)
			{
			    	if(k != 0 &amp;&amp; chk_str[j-1] == ch || chk_str[j-1] == ch2)
				{
			    		new_str[i][k] = ch;
					k++;
				}
	    			new_str[i][k] = chk_str[j];
				k++;
			}
		}
		cout &lt;&lt; new_str[i] &lt;&lt; endl;	
		len_new_str[i] = strlen(new_str[i]);
		cout &lt;&lt; "Length of the string: " &lt;&lt; len_new_str[i] &lt;&lt; endl;
		margin = (60 - len_new_str[i])/2;
		for(l=0;l&lt;margin;l++)
		{
		    cout &lt;&lt; ch;
		    ofp &lt;&lt; ch;
		}
		cout &lt;&lt; new_str[i] &lt;&lt; endl;	
		ofp &lt;&lt; new_str[i] &lt;&lt; endl;	
	}
	ofp.close;
	return 0;
}
</PRE></BODY></HTML>
