Program doesn't execute.
Apr 27, 2015 at 5:23pm UTC
I am trying to check if my input from file is correct and it seems that I did something wrong which seems to make the program loop forever.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#include <fstream>
using namespace std;
const char CDfv[] = "U2.txt" ;
const char CRfv[] = "U2rez.txt" ;
const int CMax = 100;
struct Sokejas
{
char pav[20];
int techn[10];
int artist[10];
int balai;
};
int poru_sk,
teis_sk;
Sokejas Mas[CMax];
void Skaityti(Sokejas Mas[])
{
ifstream fd (CDfv);
fd >> poru_sk >> teis_sk;
for (int i = 0; i < poru_sk; i++)
{
fd >> Mas[i].pav;[i]
for (int j = 0; j < teis_sk; i++)
{
fd >> Mas[i].techn[j];
}
for (int k = 0; k < teis_sk; i++)
{
fd >> Mas[i].artist[k];
}
}
fd.close();
}
void Spausdinti(Sokejas Mas[])
{
ofstream fr (CRfv);
fr << poru_sk << teis_sk;
for (int i = 0; i < poru_sk; i++)
{
fr << Mas[i].pav;
for (int j = 0; j < teis_sk; i++)
{
fr << Mas[i].techn[j];
}
for (int k = 0; k < teis_sk; i++)
{
fr << Mas[i].artist[k];
}
}
fr.close();
}
int main()
{
Skaityti(Mas);
Spausdinti(Mas);
}
I bet the problem is somewhere in this part, not quite sure where. I read that ignore(), but no thoughts on how to implement it or even if that helped.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void Skaityti(Sokejas Mas[])
{
ifstream fd (CDfv);
fd >> poru_sk >> teis_sk;
for (int i = 0; i < poru_sk; i++)
{
fd >> Mas[i].pav[i];
for (int j = 0; j < teis_sk; i++)
{
fd >> Mas[i].techn[j];
}
for (int k = 0; k < teis_sk; i++)
{
fd >> Mas[i].artist[k];
}
}
fd.close();
}
Here is the input file
1 2 3 4 5 6 7 8 9 10
3 5
Petras Rasa
3 1 5 8 10
5 6 7 8 9
Rita Jurgis
6 5 8 5 8
9 8 7 6 5
Rasa Linas
10 10 10 10 10
8 8 8 8 8
Apr 27, 2015 at 10:34pm UTC
On lines 26 and 30 your loops are incrementing the wrong variable.
Apr 28, 2015 at 9:26am UTC
Uh, stupid me. Thank you!
Now the output is not the same as input.
Input:
1 2 3 4 5 6 7 8 9 10
3 5
Petras Rasa
3 1 5 8 10
5 6 7 8 9
Rita Jurgis
6 5 8 5 8
9 8 7 6 5
Rasa Linas
10 10 10 10 10
8 8 8 8 8
Output:
35Petras000000000000000000000000000000
It should be same, though.
Apr 28, 2015 at 9:35pm UTC
Extending on MrGoat's post, also lines 45 and 49 need changing.
Topic archived. No new replies allowed.