SoundSim
arraytest.c
Go to the documentation of this file.
1 /*
2 
3  * test1.c
4  *
5  * Created on: 04.09.2015
6  * Author: juliusplehn
7  */
8 #include <stdio.h>
9 #include <stdlib.h>
10 int index_array(int *arr, size_t rows, int x, int y)
11 {
12  return arr[x * rows + y];
13 }
14 
15 int main(int argc, char **argv) {
16 
17  size_t rows = 0;
18  size_t cols = 4;
19  int realcount = 0;
20  int *sendarray = 0;
21  if(realcount==rows){
22  size_t newnum = (rows + 2) * 2;
23  int *newptr = realloc(sendarray, newnum * cols * sizeof(*sendarray));
24  rows = newnum;
25  sendarray = newptr;
26  }
27  //int *arr = malloc(rows * cols * sizeof(*arr));
28  //ausgewählte Zeile mal Anzahl der Zeilen + Spalte
29  sendarray[realcount * rows + 1] = 5;
30  ++realcount;
31  sendarray[realcount * rows + 10] = 30;
32  ++realcount;
33  int arr_1_1 = index_array(sendarray, rows, 0, 1);
34  int arr_4_1 = index_array(sendarray, rows, 1, 10);
35  int arr2 = index_array(sendarray, rows, 1, 1);
36  int arr3 = index_array(sendarray, rows, 100, 0);
37  printf("1,1: %d\n",arr_1_1);
38  printf("4,1: %d\n",arr_4_1);
39  printf("arr2: %d\n",arr2);
40  printf("arr3: %d\n",arr3);
41 }
42 
int index_array(int *arr, size_t rows, int x, int y)
Definition: arraytest.c:10
int cols
Definition: main.c:29
int rows
Definition: main.c:26
int main(int argc, char **argv)
Definition: arraytest.c:15