I've attempted to create a dynamic char array:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void push(int *rows, char **arr, char *value) {
int colum = strlen(value);
arr = malloc(*rows * sizeof(char *));
arr[*rows] = malloc(colum * sizeof(char));
arr[*rows] = value;
printf("%s\n", arr[*rows]);
// increment rows variable
(*rows)++;
}
int main() {
int rows = 0;
char **arr = NULL;
arr = malloc(sizeof(char) * sizeof(char *));
push(&rows, arr, "test");
printf("%s", arr[0]);
}
This outputs:
test
(null)
Indicating that the value test
is not being stored into the **arr
pointer array correctly.
I want to print the contents of **arr
, what am I doing wrong?