Good evening.
I'm having a problem using an array as a parameter in my functions. I have a function that has an int array as a parameter, when I call the array an original array, and in the function I manipulate the parameter and saved in an external file, the problem is in the manipulation part, when I manipulate the parameter, the values of the original matrix are being modified too, and it is not for them to be modified, it is for only the value of the parameter matrix being modified. It may have been a bit confusing but I believe that seeing the code will understand:
Part where I create the original array:
FILE *pgm;
do
{
char arq[30];
printf("Digite o nome de arquivo para leitura com .pgm no fim(ex: imagem.pgm): ");
setbuf(stdin, NULL);
gets(arq);
pgm = fopen(arq, "r");
}while(pgm == NULL);
char tipo[5];
fscanf(pgm, "%s", &tipo);
fscanf(pgm, "%d %d", &col, &lin);
fscanf(pgm, "%d", &escala);
int img[lin][col];
for(i = 0; i < lin; i++)
{
for(j = 0; j < col; j++)
{
fscanf(pgm, "%d", &img[i][j]);
}
}
fclose(pgm);
Function that uses an array as a parameter:
void escurerClarear(char tipo[], int mat[lin][col]){
float mult;
system("cls");
printf("Informacoes:\n\nPara clarear/escurecer e necessario fornecer um multiplicador com ou sem casa decimal\n\nEsse multiplicador deve ser maior que 0\n\nUm valor abaixo de 1 escurece a imagem e acima de 1 clareia\n\nDigite um multiplicador: ");
scanf("%f", &mult);
while(mult < 0)
{
printf("\n\nO multiplicador deve possuir valor positivo: ");
scanf("%f", &mult);
}
for(i = 0; i < lin; i++)
{
for(j = 0; j < col; j++)
{
if((mult * mat[i][j]) > escala)
{
mat[i][j] = escala;
}
else
{
mat[i][j] = mult * mat[i][j]);
}
}
}
salvarImg(tipo, mat);}
Calling the function:
escurerClarear(tipo, img);
After executing the function the values of the img array are being changed and I do not want modificalos, I want to modify only the values of the mat matrix of the
EDITION ::
int temp[lin][col];
for(i = 0; i < lin; i++)
{
for(j = 0; j < col; j++)
{
temp[i][j] = img[i][j];
}
}
escurerClarear(tipo, temp);