N
N
Nikita Markelov2013-11-26 23:56:17
C++ / C#
Nikita Markelov, 2013-11-26 23:56:17

What is strange about the cycle?

#include <fstream>
using namespace std;
char a[100][100];
int i,j,m,n,r;
main()
{
    ifstream in("input.txt");
    ofstream out("output.txt");
    in>>m>>n;
    for (;i<m; i++)
        for (;j<n; j++)
        in>>a[i][j];
}

Used by MinGW. Can you explain why the loop doesn't work? "i" and "j" are zero, exactly less than "m" and "n" but the loop is not completely executed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lolshto, 2013-11-27
@Entii

What do you mean ignored? It's just that after the first execution of the inner loop, j will remain equal to n, and therefore the inner loop will be executed only once. (it's still lucky that in C++ global variables are initialized to zero)
And all because my mother told me to declare variables as close as possible to the place of use :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question