Allocate memory for struct : Struct Size « Structure « C / ANSI-C






Allocate memory for struct

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

 

struct address {
  char name[400];
  char street[400];
  char city[400];
  char state[30];
  char zip[100];
};

int main()
{
  struct address *p;

  if((p = malloc(sizeof(struct address)))==NULL) {
    printf("Allocation Error\n");
    exit(1);
  }
  return p;
}

           
       








Related examples in the same category

1.Get the size of a struct