Untitled

                Never    
C/C++
       
#include <stdio.h>
#include <stdlib.h>

struct student {
  const char *name;
  const char *address;
} students[] = {
    { "Jhon",    "UK" },
    { "Doe",    "USA" },
    { NULL }
};


int prStruct(struct student *stu);

int main(void){
	struct student *sta;
	struct student *stb;
	sta = malloc(2*sizeof(*sta));
	//sta = students;
	
	
	stb = realloc(sta, 6*sizeof (*sta));
	char *nama[] = {"Agus","Bonny", "Chika", "Dennis", "Eddy", "Farah"};
	char *alamat[] = {"AA","BB","CC","DD","EE","FF"};

	if (stb){
		int i = 0; int n = 6;
		for (i = 0;i < n; i++){
			(stb+(i*sizeof(*stb)))->name = nama[i];
			(stb+(i*sizeof(*stb)))->address = alamat[i];
		}
		(stb+(i*sizeof(*stb)))->name = NULL;
		(stb+(i*sizeof(*stb)))->address = NULL;
		prStruct(stb);
	}
	
	return 0;
}
	

int prStruct(struct student *stu){
	//fprintf(stdout,"%s\n", (stu+(2*sizeof(*stu)))->name);
	for (stu=stu;stu->name;stu++){
		fprintf(stdout,"%s\n", stu->name);
	}
	return 0;
}

Raw Text