Hello. I am working on a C program that reads in an input file with a bunch of addresses in alphabetical order and outputs the names and addresses to another file sorted by zip code. The program uses array of pointers to structures and malloc with no global variables. I have written the input and output functions thus far. Still working on the sort function. My program is outputting strange characters when I run it. I have 3 files with the following code so far:

record.h
Code:
#define size 40
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct{
	char name[size];
	char address[size];
	char citystate[size];
	char zipcode[size];
}CITYRECORDS;

typedef CITYRECORDS *CRP;
CRP p;

void readin(CITYRECORDS *city[], int num);
void writot(CITYRECORDS *city[], int num);
record.c
Code:
#define MAXCITYREC 50
#include "record.h"

char buffer[81];

void readin(CITYRECORDS *city[], int num){
	num=0;

	while((gets(buffer)!=NULL)&&(num<MAXCITYREC)){
		p=(CRP)malloc(sizeof(CITYRECORDS));
		strcpy(p->name, buffer);
		gets(p->address);
		gets(p->citystate);
		gets(p->zipcode);
	}
	city[num++]=p;
	free(p);
}

void writot(CITYRECORDS *city[], int num){
/*	CITYRECORDS *p;*/
	
	for(p=*city;p<*city+num;p++){
		printf("%c %c %c %c\n", p->name, p->address, p->citystate, p->zipcode);
	}
}
prog6b.c
Code:
#define CITIZENS 50
#include "record.h"

void main(void){
	CITYRECORDS *city[50];
	int n=CITIZENS;

	readin(city, n);
	writot(city, n);
}
I am getting the following output in the file after I run the program.

è  8 `
ˆ ° Ø
( P x ..
È ğ  @
h ¸ à
 0 X €
¨ Ğ ø
H p ˜ À
è  8 `
ˆ ° Ø
( P x ..
È ğ  @
h ¸ à
 0 X €
¨ Ğ ø
H p ˜ À
è  8 `
ˆ ° Ø
( P x ..
È ğ  @
h ¸ à
 0 X €
¨ Ğ ø
H p ˜ À
è  8 `
ˆ ° Ø
( P x ..
È ğ  @
h ¸ à
 0 X €
¨ Ğ ø
H p ˜ À
è  8 `
ˆ ° Ø
( P x ..
È ğ  @
h ¸ à
 0 X €
¨ Ğ ø
H p ˜ À
è  8 `
ˆ ° Ø
( P x ..
È ğ  @
h ¸ à
 0 X €
¨ Ğ ø
H p ˜ À
è  8 `
ˆ ° Ø
Any help on how to fix this will be greatly appreciated.