[ create a new paste ] login | about

Link: http://codepad.org/J1XrFwQu    [ raw code | output | fork ]

C, pasted on Jul 16:
#include <stdio.h>

#define X 5
#define Y 7

void output(char *ary[]) {
  int i, j;
  for (i = 0; i < Y; i++) {
    for (j = 0; j < X; j++)
      printf("%c,", ary[i][j]);
    putchar('\n');
  }  
  putchar('\n');
}
  
void func(char *ary[], int x, int y) {
  ary[y][x] = ary[y][x] - 'a' + 'A';
}

int main() {
  int i, j;
  static char a[Y][X];
  char *b[Y];

  /* initialize */
  for (i = 0; i < Y; i++)
    for (j = 0; j < X; j++)
      a[i][j] = 'a' + i + j;

  /* for passing to func,  need to do */
  for (i = 0; i < Y; i++)
    b[i] = &a[i][0];

  func(b, 0, 1);
  output(b);
  func(b, 2, 3);
  output(b);
  func(b, 4, 5);
  output(b);

  return 0;
}
/* end */


Output:
a,b,c,d,e,
B,c,d,e,f,
c,d,e,f,g,
d,e,f,g,h,
e,f,g,h,i,
f,g,h,i,j,
g,h,i,j,k,

a,b,c,d,e,
B,c,d,e,f,
c,d,e,f,g,
d,e,F,g,h,
e,f,g,h,i,
f,g,h,i,j,
g,h,i,j,k,

a,b,c,d,e,
B,c,d,e,f,
c,d,e,f,g,
d,e,F,g,h,
e,f,g,h,i,
f,g,h,i,J,
g,h,i,j,k,



Create a new paste based on this one


Comments: