i have a txt file, it has series like:
1
a
2
b
.
.
.
12
l
*
.
.
.
something like this..and i wanted to print the text till * when it finds 12..but my code keeps on printing 12,12,12...for infinite times...please chk my code.
please ignore the random number part becoz i was trying to do it with any random number. anyway that loops does not make any difference...
it worked mann...thanx..but 1 more thing, i want it to stop printing as soon as it finds * i tried placing the break statement at some places where i thought it would work but its not working..can u please have a look at it.?
// readin.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
int main ()
{
char answer;
int min=1,max=100,c[100]={0};//c is started from 0 value since i want to make sure that a random no should never be
//repeated and if repeated, should be checked one prior to the latest no generated
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
for (int i=1; i<=100; i++)
{again:
int randNum = rand()%(max-min + 1) + min;
c[i]=randNum;
for (int j=1; j<=100; j++)
{
if (c[j-1]==randNum) //[0 12 41 56 41]
goto again;
else
{
while ( getline (myfile,line) )
{
if (line == "12")
{
while ( getline (myfile,line) )
{
if (line == "*")
break;
else
cout << line << '\n';
}
}
}
}
}
myfile.close();
}
}
else cout << "Unable to open file";
return 0;
}