How to use functions. Help please

Hi everyone!
I'm trying to use functions for the first time and I don't know how to do use them.

for example:
if my input is :
66
1 2 1 0 0 0 2 2 2 2 2 1 1 2 1 0 3 1 0 0 1 1 1 1 1 2 1 0 1 1 0 1
1 2 1 0 1 1 0 1 1 2 1 0 0 0 2 2 0 2 2 2 0 1 2 2 0 1 2 2 2 1 1 2 1 0
4 5 8
my output would be like:
1 2 1 0 0 0 2 2
2 2 2 1 1 2 1 0
3 1 0 0 1 1 1 1
1 2 1 0 1 1 0 1
1 2 1 0 1 1 0 1

0 2 2 2 2 2 1 1
2 1 0 3 1 0 0 1
1 1 1 1 2 1 0 1
1 0


And that's ok it works just fine, but what I'd like to do is to use 2 functions one for the lines l(n) and one for the part X[N][][] like part0,1ecc ecc
to have in output this:

part 0
l0:1 2 1 0 0 0 2 2
l1:2 2 2 1 1 2 1 0
l2:3 1 0 0 1 1 1 1
l3:1 2 1 0 1 1 0 1
l4:1 2 1 0 1 1 0 1
part 1
l0:1 2 1 0 0 0 2 2
l1:0 2 2 2 0 1 2 2
l2:0 1 2 2 2 1 1 2
l3:1 0


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
  #include <iostream>
#include <fstream>
using namespace std;
void strato(ofstream&out)
	{
		cout<<"strato"<<" ";
	}
		
int main()
{
	ifstream IN("input");
	ofstream OUT("output");
	if (IN && OUT)
	{
		int n_el, val=0; //Leggo array A[400]
		int X[400];
		IN>>n_el;
		for(int i=0; i<400 && val<n_el; i++)
			{
				IN>>X[i];
				val++;
			}	
			val=0;
			int a, b, c;
			IN>>a>>b>>c;
			int Z[a][b][c];
				for(int j=0; j<a && val<n_el; j++)
				{
				for(int k=0; k<b && val<n_el; k++)
						{
							for(int l=0; l<c && val<n_el;l++)
							{
								Z[j][k][l]= X[b*j + c*k +l];
								OUT<<Z[j][k][l]<<" ";
								val++;
							}
							OUT<<"\n";
						}
						OUT<<" \n";
				}
	}
	else
	cout<<"errore con i files";
	IN.close(); OUT.close();    
	}




any help???
Last edited on
if my input is :
...

my output would be like:
...

More exact syntax description, please.

Line 26 is not standard C++. See variable length arrays (VLA).

I wonder what your "use function" means. On lines 37 and 39 you do call a function called operator<<. The line 39 executes at the end of each "part". That line is at the end of a scope; the cloisng brace is on line 40. Where is the opening brace of that scope, i.e. where does that block start?
Topic archived. No new replies allowed.