Please some one help me with this..
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct{
int id;
char nama[50];
} test_t;
void test(int* count, test_t* t){
(*count) = 5;
t = (test_t*)malloc(sizeof(*t)*5);
for(int i=0;i<5;i++){
t[i].id = i;
strcpy(t[i].nama, "test");
printf("id: %i\nnama: %s\n", t[i].id, t[i].nama);
}
printf("t size: %lu\n", sizeof(t));
}
int main(int argc, char** argv){
int a = 1;
test_t* item;
test(&a, item);
for(int i=0;i<a;i++){
printf("id: %i\nnama: %s\n", item[i].id, item[i].nama);
}
return 0;
}
i try to pass pointer to a struct and then make array from it then return the array to calling function.. but i cant get result from that.. any help would be appreciated.. thank you...
btw.. this is the output result
id: 0
nama: test
id: 1
nama: test
id: 2
nama: test
id: 3
nama: test
id: 4
nama: test
t size: 8
id: 1
nama:
id: -767851619
nama: �
id: -767851396
nama: �
id: -767849773
nama: �
id: -767849398
nama: �