To create a text file (.txt) in C lang
How to open a text file („daten.txt“) in the language C here in my Fedora 41 (Linux).
The new program shows the current time. The telephone number does not appear here.
#include <stdio.h>
#include <time.h>
int main(){
FILE *fp;
fp = fopen("daten.txt", "w");
if (fp == NULL) {
fprintf(stderr, "Datei konnte nicht erstellt werden. \n");
return 1;
}
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
char name[50];
printf("Insert your name: ");
scanf("%s", name);
fprintf(fp, "\nHallo %s heute ist %s", name, asctime(timeinfo));
fclose(fp);
// printf( "\nHallo %s heute ist %s", name, asctime( timeinfo));
return 0;
}
