Array size from first line of file

i am trying to create an array with the size of the first value of one file wich is the same of the first line because the first line only have one value

here is how i am trying to do it
FILE * fich;
int test;
fich=fopen(nome_ficheiro,"r");
fscanf_s(fich,"%d",&test);
int np=test;
No*aux=primeiro;
ponto pontos[np];


but it is giving me this erros:
1>c:\users\daniel\documents\trabalhos\eda\tp6\marcos\poligono.cpp(219) : error C2057: expected constant expression
1>c:\users\daniel\documents\trabalhos\eda\tp6\marcos\poligono.cpp(219) : error C2466: cannot allocate an array of constant size 0
1>c:\users\daniel\documents\trabalhos\eda\tp6\marcos\poligono.cpp(219) : error C2133: 'pontos' : unknown size


can somone help me?
Since VLA are not allowed in C++ you will either need to use dynamic memory or better yet investigate std::vectors. Remember that the size of an array in C++ must be a compile time constant.
you'll have to do this:
1
2
3
4
5
6
7
FILE * fich;
int test;
fich=fopen(nome_ficheiro,"r");
fscanf_s(fich,"%d",&test);
int np=test;
No*aux=primeiro;
ponto* pontos = new ponto[np];


But when you are done with pontos, you also need to remember to do this:
delete[] pontos;
i did this and putted to delete the pontos but now it abortes the program when it gets to that part of the program
Topic archived. No new replies allowed.