Unless I am missing something, simply adjust your fprintf statement to not include the column names. Then an initial logging line to generate the table headers.
int main()
{
/* declarations*/
logfile=fopen(filename,"w+");
if (logfile != NULL)
{
fprintf(logfile, "Type,SA,DA,UDP Length,UDP Checksum\n");
}
/*related stuffs*/
}
void print_udp_packet(unsigned char *Buffer , int Size)
{
/*ip header length related codes*/
fprintf(logfile , "%s,%d,%d,%d,%d\n",
"UDP",
ntohs(udph->source),
ntohs(udph->dest),
ntohs(udph->len),
ntohs(udph->check));
}