I need to print a L1 line of a matrix in C

Asked

Viewed 40 times

-2

After reading L1 in main, I need to pass line A[L1] to a function and print this line Prints(A[L1]), only it gives an error saying that it does not recognize the parameter. What can it be?

void Imprime(float *A[l1]) {
    float *p;
    for(p = A[l1]; p < A[l1] + MAXCOL; p++) {
            printf("%.2f ", *p);
        }
        printf("\n");
}

1 answer

2

Good afternoon,

I think your problem lies in how you pass the matrix as a parameter. Not being sure what you want, I made a small example of what I think I realized you want.

Don’t forget that the numbering of rows and columns starts from zero, so when I say I want to print line 1, I’m actually saying I want to print the second line.

        #include <stdio.h>
        #include <stdlib.h>

        //Definicao da tabela
        #define linhas  3
        #define colunas 3

        //Assinatura do metodos
        void ImprimirLinha(double matriz[linhas][colunas], int linhaQueQueroImprimir);

        int main()
        {
            
            double matriz[linhas][colunas] = {  1.1 , 2.2 , 3.3 ,
                                                4.4 , 5.5 , 6.6 , 
                                                7.7 , 8.8 , 9.9 
                                              };
            int linhaQueQueroImprimir = 1;
            ImprimirLinha(matriz, linhaQueQueroImprimir);

        }

        void ImprimirLinha(double matriz[linhas][colunas], int linhaQueQueroImprimir)
        {
            
            for(int i = 0; i<colunas; i++ )
            {
                printf("%0.3f |", matriz [linhaQueQueroImprimir] [i] );
            }
            printf("\n");
        }

I hope I have helped, if so please please give up vote.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.