5
My program runs, but right after asking for the value prob()
the .exe
stop working.
I thought it was some communication problem between functions on account of the matrix lattice[][4]
as an argument, but I have already searched, set up and the same thing keeps happening. I am almost sure that the problem lies in the communication between the main()
and the label()
.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int random();
float prob();
int label(float lattice[][4],float);
int i, j;
int random() /* Sorteia um número entre de 0 a 1 */
{
float x;
srand((unsigned)time(NULL));
x = rand()%100+1;
x = x/100;
return x;
}
float prob()
{
float p;
printf("Probabilidade: ");
scanf("%f", &p);
return p;
}
int label(float lattice[][4], float p)
{
for(i=0; i<4 ; i++)
for(j=0; j<4; i++)
{
lattice[i][j] = random();
}
for(i=0; i<4; i++)
for(j=0; j<4; j++)
{
if(lattice[i][j] <= p)
lattice[i][j] = 1;
else
lattice[i][j] = 0;
}
return 0;
}
int main()
{
float lattice[4][4];
float p = prob();
label(lattice, p);
system("pause");
return 0;
}
Does it give any error? Edit and put the
include
s or anything else the code has. http://answall.com/help/mcve. De ccara I saw that your code does not even compile.– Maniero
had not put complete, because the rest is all good, the business is the main() and the label(). But Taí, the complete code...
– Higor
Boy, ta compiling here. But as I said, the . exe hangs after asking 'Probability': ''...
– Higor
Did you debug? It hangs where exactly inside the function
prob
? Would be in thescanf
? Locking is consistent (i.e., always occurs)?– Luiz Vieira