How to skip the new line in file reading

I'm reading the text from file sentence by sentence, I'm using the full stop(.) as a delimiter. If there is a new line character in between a sentence, how can i skip it??? like the text bellow:
Note:(File text cannot be changed)

--------Text--------
An aeroplane is in the sky. The rose is red. A
girl is playing there. Numbers are not
allowed in the password. There is a
playground.
--------------------


------------Code------------
#include<iostream>
#include<fstream>
using namespace std;

int main()
{
char sen[50] = { "\0" };
ifstream fin("text.txt");
while (!fin.eof())
{
fin.getline(sen, 49, '.');
cout << sen << endl;
}
}
---------------------------------------


--------------Out put---------------
An aeroplane is in the sky
The rose is red
A
girl is playing there
Numbers are not
allowed in the password
There is a
playground
---------------------------------------


------------Expected Output--------------
An aeroplane is in the sky
The rose is red
A girl is playing there
Numbers are not allowed in the password
There is a playground
-------------------------------------------
@Talha Bin Adam

Fun project. I also included the periods in each of the sentences, and they are each on a separate line, as you show above.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include <string>
#include<fstream>
using namespace std;

int main()
{
	string sentence, rest = "";
	int x, len;
	ifstream fin;
	fin.open("Text.txt");
	while (fin)
	{
		getline(fin, sentence);
		len=sentence.length();
		for(x=0;x<len;x++)
		{
			if(sentence[x] != '\0')
				rest+=sentence[x];
			if(sentence[x] == '.')
			{
				cout << rest  << endl;
				x++; // To remove space after period
				rest = "";
			}
		}
		rest+=" ";
	}
	cout << endl << endl;
	fin.close();
}
I don't want to do this using string. I have to do this only with char array...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
   bool pre = true; 
   char c;
   ifstream in( "text.txt" );
   while ( in.get( c ) )
   {
      if ( c == '.' )
      {
         cout << '\n';
         pre = true;
      }
      else if ( c == '\n' || c == ' ' )
      {
         if ( !pre ) cout << ' ';
      }
      else
      {
         cout << c;
         pre = false;
      }
   }
   in.close();
}
An aeroplane is in the sky
The rose is red
A girl is playing there
Numbers are not allowed in the password
There is a playground

Topic archived. No new replies allowed.