garbage value in C array -


i trying write c code print pyramid structure on screen, this.

enter image description here

the corresponding code i've written this.

 #include <stdio.h>  #include <stdlib.h>  void printarrayfunc(char arr[9][5]) {     int i,j;     printf("=========================================\nprinting values\n");     (i = 0; i<5; i++)     {         (j = 0; j<9;j++)         {             //printf("arr[%d][%d] = %d\n", i,j, arr[i][j]);             if (arr[i][j] == 1)                 printf("*");             else                 printf(" ");         }         printf("\n");     } }   int main() {     int i,j;     char arr[9][5] = {0};      printf("============================\nfilling values\n")    ;     (i=0;i<5;i++)     {         (j= 4-i;j<=4+i;j++)         {             arr[i][j] = 1;             // printf("arr[%d][%d]= %d\n",i,j,arr[i][j]);         }         //printf("\n");     }     printarrayfunc(arr);      return 0; } 

it giving output like

enter image description here

i know i'm doing silly mistake @ moment, i'm not able find going wrong. let me hear comments on this.

in function argument:

char arr[9][5] 

in loop:

for (i = 0; i<5; i++) {     (j = 0; j<9;j++) {         if (arr[i][j] == 1) 

you flipped position of i , j. i should go 0 9, j 0 5.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -