Answer the question
In order to leave comments, you need to log in
Why is the output of the program through the debugger different from the output when run from the shell?
The code is written, the purpose of which is to fill the array in random order. It is obligatory that for the same values of randvalue, the filling result remains unchanged. The algorithm is strange, yes, but what is even stranger is that when you run it several times from bash, the result of filling is different. I can't understand this with logic. I got into the GDB debugger, and there everything happens as it should be. Each time you run the program with the run command, the output remains the same. How can this be explained?
the code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define true 1
void main()
{
char a[79];
filling(a, 1);
}
void filling(char *rotor, int randvalue)
{
int tmp = 0;
int number = 0;
int findflag = 0;
int launchflag = 1;
int i = 0;
srand(randvalue);
while(launchflag)
{
tmp = rand()%79;
printf("%d\n", tmp);
for(i; i<79; i++)
{
if(rotor[i]==tmp)
{
findflag = 1;
break;
}
}
if(findflag==0)
{
rotor[number] = tmp;
number++;
i=0;
}
if(findflag==1)
{
i=0;
findflag = 0;
}
if(number == 78)
{
launchflag = 0;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question