void generate( int *A, int m, int s, int n);//impl. is left out for the //sake of berevity. it just fills the array with random numbers
int main( )
{ int *A; //Array to hold numbers
int i, j, k; //Loop indices
long n = 3, r = 5; //Used as the range for numbers
long m = 3; //m numbers will be generated
long iSize = r - n + 1;
A = newint[iSize];
for(int j=0;j<iSize;++j)
cout << "here";// << A[j];
generate(A, m, iSize, n);
for(int j=0;j<m;++j)
cout << A[j];
while(1);
return 0;
}
Why? It's original. OP is making an effort to hold the screen open without copping out and using a system call. Sure it spikes their CPU and you can't just press a key to exit but it shows creativity. I have without a doubt seen worse ways of doing this.
And who are you to criticize? Mr.:
if i run this i do get some (garbage to the screen).
I hope you realize that this is normal behavior when you try to print out data from an uninitialized array. Without the content of the "generate()" function how can you even pretend to know what is in OPs array?
I'm applauding originality. Why don't you like it? Because you don't know what to press to exit it? Try Ctrl+C, you should be running console applications from within the command prompt anyway. You're the one expecting to see meaningful data in an array that doesn't have values set. Would you like to see a poll here on which one people consider to be dumber?
thats actually quite a clever way of keeping it open. we could all get pissed at him for using system("pause") or cin.get() without checking the buffer, but he found a sure fire way to keep it open. i have never seen an intentional inifinite loop used that way and is good for practicing writing software
void generate( int *A, int m, int s, int n)
{
/*********initialize random seed*********/
srand( time(0) );
for(int i = 0;i<10;++i)
A[i] = rand() % s + n;
}
It looks like you're app is crashing. The size of you array is being calculated as 'r - n + 1', 'r' equaling '5' and 'n' equaling '3' plus '1' gives us a number less then '10'.
If you are getting a 'permission denied' error then that is completely different from 'nothing is printing to the screen'.
Permission denied usually means the file you are trying to over write when you compile your project is still open, that is of course assuming you have write permissions on the target directory. Check your running processes and kill it if it is there, if you don't see it then try rebooting the PC to release any weird file locks that might be on it.
I'm not really a *Nix guy so someone else correct me if I'm wrong, but isn't 'a.out' the default output FOLDER for GCC and not the executable name itself?