Error copying an array in another in c

0

The truth happens to me something very strange is that I copy one matrix in another as I have always done but it is badly copied I leave photo .

As you can see in the photo, the first 3 columns are copied well, but 4 copies the first one with a space down and then copies what is in the 4 column in the last one without reason (there must be a reason but there is no which is), if someone knows why it happens I would be grateful I'll leave the code.

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <string.h>
#include <time.h>

int main(){

        char *p=getenv("USER");
        char frase[1024];

        printf("  [>>] Entroduce un frase para cifrar.\n" );
        printf("    %s~$ ",p );
        scanf("%s", frase);

        int clavei[3][3];
        int subclave[3][43];
        int rotword[3][0];

        int x,y;
        int nram;
        int i,j;
        int aux; 

        for(i=0 ; i<=3 ; i++){
                for(j=0 ; j<=3 ; j++){
                        nram =  0 + rand() % ((255 + 0) - 0);
                        clavei[i][j] = nram;
                        printf("%x ,", clavei[i][j]);
                }

                printf("\n");
        }

        printf("------------------------------------------------------------------------------------------------------------------------------------------");
        printf("\n");                                                   
        for(i=0 ; i<=3 ; i++){
                for(j=0 ; j<=43 ; j++){
                        subclave[i][j] = 0;
                }
        }

        for(i=0 ; i<=3 ; i++){
                for(j=0 ; j<=3 ; j++){
                        subclave[i][j] = clavei[i][j];
                }

        }


        for(i=0 ; i<=3 ; i++){
                for(j=0 ; j<=43 ; j++){
                        printf("%x ,", subclave[i][j]);
                }

                printf("\n");
        }

        printf("\n");
        printf("  Adios :)\n");                                         
        return 0;                                                                       
}
    
asked by Frijolito 30.11.2018 в 21:58
source

1 answer

0

The solution to your problem is to take out in the cycles for the condition of less or equal estrico, I add images showing the erroneous performance when leaving the equal. We see how the last column takes erroneous values, while the internal columns take the values they should have. But if we take the least equal, the following happens:

It takes the correct values, without jump that I am getting from my accumulator. I hope you understand.

    
answered by 30.11.2018 в 22:55