47 lines
1.4 KiB
C
47 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int main(){
|
|
char name[50], vorname[50], strasse[50], hausnummer[50], plz[50], wohnort[50], telefon[50], fax[50];
|
|
int n;
|
|
|
|
char *filename = "adresse.txt", *ptr;
|
|
printf("Dieses Programm liest eine Adresse ein und schreibt\ndiese Adresse n mal in die Datei 'adresse.txt'\n");
|
|
|
|
printf("Vorname:");
|
|
fgets(vorname, sizeof(vorname), stdin);
|
|
printf("Nachname:");
|
|
fgets(name, sizeof(name), stdin);
|
|
printf("Strasse:");
|
|
fgets(strasse, sizeof(strasse), stdin);
|
|
printf("Hausnummer:");
|
|
fgets(hausnummer, sizeof(hausnummer), stdin);
|
|
printf("Postleitzahl:");
|
|
fgets(plz, sizeof(plz), stdin);
|
|
printf("Wohnort:");
|
|
fgets(wohnort, sizeof(wohnort), stdin);
|
|
printf("Telefon:");
|
|
fgets(telefon, sizeof(plz), stdin);
|
|
printf("Fax:");
|
|
fgets(fax, sizeof(fax), stdin);
|
|
|
|
printf("Wie oft soll Adresse in Datei geschrieben werden:");
|
|
scanf("%d", &n);
|
|
|
|
ptr = strchr(strcat(vorname, name), '\n');
|
|
ptr[0] = ' ';
|
|
ptr = strchr(strcat(strasse, hausnummer), '\n');
|
|
ptr[0] = ' ';
|
|
ptr = strchr(strcat(plz, wohnort), '\n');
|
|
ptr[0] = ' ';
|
|
|
|
FILE *fp = fopen(filename, "w");
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
fprintf(fp, "%s%s%s\nTel. %sFax %s", vorname, strasse, plz, telefon, fax);
|
|
fprintf(fp, "--------------------------------------------------\n");
|
|
}
|
|
|
|
fclose(fp);
|
|
} |