I've written a program which takes one file after the other as input and process them and send the result to an output file.
But now I'm getting weird situation
where my for loop is either executing the loop from k=1 to k=63 (producing output from k=1 to 63)
or from k=64 to k=122 (producing output from k=64 to 122)
but not from k=1 to k=122 directly.
If I try to run the program for k=1 to k=122 then it produces output upto k=63 iteration and does nothing.
The for loop that causes this problem is in main block.
Here's my code
#include<bits/stdc++.h>
using namespace std;
int solve()
{
int total=0;
int noOfBalls=0;
int wicket=0;
string input,country1,country2,battingFirst;
int scoreOfBall;
string Extras,Type,variable,Total;
int f=1,l=1;
for(;(cin>>input) && f;)
{
if(input=="match_type:") {
cin>>Type;
if(Type=="ODI") {f=1;}
else {f=0;cout<<endl;}
}
if(input=="teams:")
{
scanf("-%s-%s",country1,country2);
}
if(input=="team:")
{
f=0;
cin>>battingFirst;
cout<<battingFirst<<"\t\t";
goto a1;
}
}
First, please use code tags. On an initial post you have to type them in manually ([ code] and [/ code], but without the spaces). Then paste your code between the tags. Indentation will be preserved when the code is within code tags.
For subsequent posts and if you edit your post, simply click the "<>" format button to generate the tags. You can edit your post now, highlight your code, and click the "<>" format button. (Indentation may or may not still be preserved at this time. We'll see.)
Second, why are you reopening stdin? Why not just open a std::ifstream and pass it as an argument to solve? You can change solve to take a std::istream& as an argument, and then you can use it with an ifstream, an istringstream or std::cin without any modification to other code. Also, there may be interactions when mixing your C++ streams (cin) with C files (freopen, stdin). I would just stay with C++ for everything.