Image

Imageprincessaverage wrote in Imagecprogramming 😛determined

more noob help requested!

I think I must have wasted too many brain cells trying to understand pointers because now I can't get a simple while loop to work with my project for my C class. Can someone please please please point out to me:

a. Why no matter where I put my scanf in a while or do/while loop in main, it doesn't stop when I enter the sentinel value of "-1"? Where should it go if I want all of the functions to keep repeating until the user enters "-1"? edit: apparently using the system("PAUSE"); screws it up.

b. I can always get my functions to work, but I don't really understand why. Does anyone know if there's a good website that really illustrates exactly how functions work?

c. Even though my code works, are there any major mistakes that I could improve on?

Thanks in advance for any advice!


(left out all the #include stuff since it messes up the lj-cut)
#define N 50


void read_array(int[], int);
void two_largest(int[], int*, int*);
void print_array(int[],int);


int main()
{
int input, i, j, array[N]={0};

read_array(array,N);
print_array(array,N);

// two_largest(array, big1, big2);


system("PAUSE");
return 0;
}

void read_array(int b[], int g) /*fn that reads in N numbers from 1-500 using srand */
{

int i,j,a[N];

srand(time(NULL));
for (i=0; i < N; i++)
{
a[i] = rand()%500+1;
}
}

void print_array(int b[], int g) /*fn that prints numbers generated in read_array fn */
{
int i,j,a[N];

for (j=0; j < N; j++)
{
printf("%d ",a[j]);
}
printf("\n");

}

void find_largest(array, biggest, bigger) /*still working on this */
{

}