Hello,
I want to pass an array to a function and change the array, how can I do that? Here's my code:
Code:
#include<stdio.h>
/*function to change the array*/
void rearng(int *qw)
{
int i,j,a;
int sa[8]; //temp array
int c = 0;
int high;
/*find highest number in the array*/
high = qw[0];
int u;
for(u = 1; u < 8; u++)
{
if(qw[u] > high)
high = qw[u];
}
/*arrange the array from high to low*/
for(i = 0; i <= high; i++)
{
for(j = 0; j < 8; j++)
{
if(i == qw[j])
{
sa[c] = qw[j];
c++;
}
}
}
/*make the temp array, real array*/
qw = sa;
}
int main(void)
{
int qw[] = {12,43,3,234,21,35,213,12}; //real array
rearng(qw); // call the function
/*problem: s not changing the real array*/
int i;
for(i = 0; i < 8; i++)
printf("%d ",qw[i]);
system("pause");
return 0;
}