Enviado em 26/10/2014 - 01:33h
meus amigos, o trecho do codigo abaixo faz parte de um projeto q tow trabalhando, sou novo na programaçao e estou com uma duvida mto dura.Enviado em 26/10/2014 - 09:38h
for(i = x; i < x+LINmtzREC; ++i) //Preenchimento da matriz recorte. { for(j = y; j < y+COLmtzREC; ++j) { for (z = 0; z < (LINmtzREC*COLmtzREC); z++) { *(pMtzRec + z) = *(pMtzOrig + (i*(y+5) + j)); //*(pMtzRec + 0) = *(pMtzOrig + (0*(y+5)+0)); //*(pMtzRec + 1) = *(pMtzOrig + (0*(y+5)+1)); //*(pMtzRec + 2) = *(pMtzOrig + (1*(y+5)+0)); //*(pMtzRec + 3) = *(pMtzOrig + (1*(y+5)+1)); } } }
Enviado em 26/10/2014 - 17:15h
ai vai o codigo todo:#include <stdio.h> #include <stdlib.h> #include <time.h> #define RANDMAX 100 //void recorte(int *pOrig, int M, int fx, int fy, int m, int n, int l, int k); //Protótipo da função recorte. int main(int argc, char *argv[]) { int LINmtzORIG, COLmtzORIG; int LINmtzREC, COLmtzREC; int x, y; LINmtzORIG = atoi(argv[1]); COLmtzORIG = atoi(argv[2]); x = atoi(argv[3]); y = atoi(argv[4]); LINmtzREC = atoi(argv[5]); COLmtzREC = atoi(argv[6]); int matrizORIG[LINmtzORIG][COLmtzORIG], *pMtzOrig = NULL; int matrizREC[LINmtzREC][COLmtzREC], *pMtzRec = NULL; int i, j, z; if (LINmtzORIG < x+LINmtzREC || COLmtzORIG < y+COLmtzREC) //Teste para saber se a matriz recorte cabe dentro da matriz original. { printf("\nMatriz recorte não cabe dentro da matriz original!\n"); exit(1); } //Ponteiros pMtzOrig = &matrizORIG[0][0]; pMtzRec = &matrizREC[0][0]; //Alocação Dinâmica, pMtzOrig = (int*) malloc(LINmtzORIG*COLmtzORIG*sizeof(int)); pMtzRec = (int*) malloc(LINmtzREC*COLmtzREC*sizeof(int)); if ((!pMtzOrig)) //Teste para saber se há memória para alocar a matriz original. { printf("Sem memória!\n"); exit(1); } if ((!pMtzRec)) //Teste para saber se há memória para alocar a matriz recorte. { printf("Sem memória!\n"); exit(1); } srand(time(NULL)); //Semente para gerar a matriz de números aleatórios. for (i = 0; i < LINmtzORIG * COLmtzORIG; i++) //Preenchimento da matriz original. { *(pMtzOrig + i) = rand() % RANDMAX; } printf("\nMATRIZ ORIGINAL:\n\n"); for (i = 0; i < LINmtzORIG; i++) //Impressão da matriz original. { for (j = 0; j < COLmtzORIG; j++) { printf("%d\t", *(pMtzOrig + i*COLmtzORIG + j)); } printf("\n"); } printf("\nMATRIZ RECORTE:\n\n"); /*for(i = x; i < x+LINmtzREC; i++) //Preenchimento da matriz recorte sem função. *(Não funciona) { for(j = y; j < y+COLmtzREC; j++) { *(pMtzRec + (i-x) + (j-y) + (i-x)) = *(pMtzOrig + i*(LINmtzORIG) + j); } }*/ //recorte(pMtzOrig, LINmtzORIG, x, y, LINmtzREC, COLmtzREC, i, j); //Impressão da matriz recorte com função. /*for (i = 0; i < LINmtzREC; i++) //impressão da matriz recorte. * { for (j = 0; j < COLmtzREC; j++) { printf("%d\t", *(pMtzOrig + i*(LINmtzORIG) + j)); //*(pMtzRec + i*COLmtzREC + j)); } printf("\n"); }*/ // for (z = 0; z < (LINmtzREC*COLmtzREC); z++) //Preenchimento da matriz recorte. // { for(i = x; i < x+LINmtzREC; i++) { for(j = y; j < y+COLmtzREC; j++) { *(pMtzRec + 0) = *(pMtzOrig + i + j); //*(pMtzRec + 0) = *(pMtzOrig + (0*(y+LINmtzREC*COLmtzREC+1)+0)); //*(pMtzRec + 1) = *(pMtzOrig + (0*(y+LINmtzREC*COLmtzREC+1)+1)); //*(pMtzRec + 2) = *(pMtzOrig + (1*(y+LINmtzREC*COLmtzREC+1)+0)); //*(pMtzRec + 3) = *(pMtzOrig + (1*(y+LINmtzREC*COLmtzREC+1)+1)); } } // } for (i = 0; i < LINmtzREC; i++) //impressão da matriz recorte. * { for (j = 0; j < COLmtzREC; j++) { printf("%d\t", *(pMtzRec + i*(COLmtzREC) + j)); } printf("\n"); } return 0; } /*void recorte(int *pOrig, int M, int fx, int fy, int m, int n, int l, int k) //Função para impressão da matriz recorte. { for (k = fx; k < fx+m; k++) { for (l = fy; l < fy+n; l++) { printf("%d\t", *(pOrig + k*(M) + l));//*(pRecorte + (k-fx) + (l-fy) + (k-fx)) = *(pOrig + k*(M) + l); } printf("\n"); } }*/
Enviado em 26/10/2014 - 17:18h
é só ter um pouquinho de atenção, pois tem uma boa parte dele comentado, foram alguns teste que fiz.Enviado em 26/10/2014 - 17:25h
Tenta primeiro pegar os valores i e j da matriz, aí sim você percorre as linhas e colunas dela (com dois for já dá pra fazer isso);Criar entrada (menuentry) ISO no Grub
Como gerar qualquer emoji ou símbolo unicode a partir do seu teclado
Instalar o VIM 9.1 no Debian 12
Como saber o range de um IP público?
Muitas dificuldades ao instalar distro Linux em Notebook Sony Vaio PCG-6131L (VPCEA24FM)
Slackpkg+ (Slackpkg Plus) está de volta!
Como dividir duas janelas igualmente e lado-a-lado na sua tela
Como redefinir o diretório Home? (4)
Problemas com adaptadores wifi no Zorin (1)
Ocomon 6.0.1 - Problemas ao editar configurações estendidas (7)