1. c-file(main):
#include "write_termin.h"
#include "w_binaer_file.h"
#include <stdio.h>
void main()
{
char filename[MAX_LEN]="daten.dat";
terminData* daten=NULL;
int anz=0;
printf("Geben Sie bitte die Anzahl Ihrer Termine ein:");
scanf("%d",&anz);
daten=write_termin(filename,anz);
write_binaer_file(filename,daten,anz);
free(daten);
}
2. c-file:
#include "write_termin.h"
#include <stdio.h>
terminData* write_termin(char filename[], int anz)
{
terminData* daten=NULL;
terminData* daten1=NULL;
int n=0;
daten=(terminData*)malloc(sizeof(terminData)* anz);
if(daten != NULL)
{
daten=daten1;
while(n<anz)
{
printf("Thema des Termins:\n");
scanf("%s",&daten1->topic);
//gets(daten1->topic);
printf("Anfangsdatum des Termins:\n");
scanf("%s",&daten1->start_date);
//gets(daten1->start_date);
printf("Enddatum des Termins:\n");
scanf("%s",&daten1->end_date);
//gets(daten1->end_date);
printf("Wer nimmt teil?\n");
scanf("%s",&daten1->user);
//gets(daten1->user);
printf("Priorität des Termins(HOCH, MITTEL, NIEDRIG:\n");
scanf("%s",&daten1->priorität);
//gets(daten1->priorität);
printf("Beschreibung des Termins:\n");
scanf("%s",&daten1->description);
//gets(daten1->description);
printf("Status des Termins(ERLEDIGT, OFFEN):\n");
scanf("%s",&daten1->start_date);
//gets(daten1->start_date);
n++;
daten1++;
}
}
else
{
printf("Memory allocation Failure!");
}
return(daten);
}
3. c-file:
#include "write_termin.h"
#include "w_binaer_file.h"
#include <stdio.h>
void write_binaer_file(char filename[],terminData* termindaten, int anz)
{
FILE* outFile=NULL;
outFile=fopen(filename,"wb");
if(outFile != NULL)
{
if(anz != fwrite(termindaten,sizeof(terminData),anz,outFile))
{
printf("error during write of %d blocks",anz);
}
}
else
{
printf("File %s could not be opened",filename);
}
fclose(outFile);
}
1. h-file:
#ifndef _write_termin_h_
#define _write_termin_h_ 1
#define MAX_LEN 100
struct struct_termin
{
char topic[MAX_LEN];
char start_date[MAX_LEN];
char end_date[MAX_LEN];
char user[MAX_LEN];
char priorität[MAX_LEN];
char description[MAX_LEN];
char state[MAX_LEN];
};
typedef struct struct_termin terminData;
terminData* write_termin(char filename[], int anz);
#endif
2. h-file:
#include "write_termin.h"
#ifndef _wbinaer_file_h_
#define _wbinaer_file_h_ 1
void write_binaer_file(char filename[],terminData* termindaten, int anz);
#endif