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

Registered users can post here. Sign in or register to post.
  • 1007451581 2018-02-22
  • 8908121580 2018-02-22
  • 141161579 2018-02-22
  • 9421578 2018-02-22
  • 2826901577 2018-02-22
  • 3647361576 2018-02-22
  • 5717551575 2018-02-22
  • 523811574 2018-02-22
  • 6439871573 2018-02-22
  • 8109431572 2018-02-22
  • 8757321571 2018-02-22
  • 5265111570 2018-02-22
  • 3351351569 2018-02-22
  • 5109361568 2018-02-22
  • 4455391567 2018-02-22
  • 9091121566 2018-02-22
  • 24791565 2018-02-22
  • 2486841564 2018-02-21
  • 9847231563 2018-02-21
  • 9264681562 2018-02-21