You want me to post the code again?
Code:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
struct CALL {
int qty;
char contract[5], owner[5], partnr[6], date1[14], date2[14];
char *callnr;
}CALL;
char *genCallNr();
void createFile(const char *Ppc, struct CALL c);
int main(void){
struct CALL c;
strcpy(c.contract, "DELL");
strcpy(c.owner, "EMEA");
strcpy(c.partnr, "615TW");
strcpy(c.date1, "030320091148");
strcpy(c.date2, "030320091148");
c.callnr = genCallNr();
printf("\n%s", c.callnr);
free (c.callnr);
printf("\n%s\t%s\t%s\t%s\n", c.contract, c.owner, c.partnr, c.callnr);
//createFile(c.callnr);
char *pc;
char cn[12];
pc = cn;
pc = genCallNr();
char *Ppc ;
Ppc = pc;
printf("\n%s", Ppc);
createFile(pc, c);
}
char *genCallNr(){
char *callnr = malloc(12);
time_t now;
struct tm *ts;
char buf[12];
now = time(NULL);
ts = localtime(&now);
strftime(buf, sizeof(buf), "1%y%m%d%H%M", ts);
//printf("\n%s", buf);
strncpy(callnr, buf,12);
// printf("\n%s", callnr);
return callnr;
}
void createFile(const char *Ppc, struct CALL c){
FILE *nf;
nf = fopen(Ppc, "w");
if (nf == NULL) {
fprintf("Can't open created file %s!\n", Ppc);
exit(1);
}
if (nf != NULL) {
fwrite(&c, 1, sizeof(CALL), nf);
fclose(nf);
}
}