Skip to content
Snippets Groups Projects
Commit c0c92216 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Beispiele 5.7.2024

parent 95cd8d3a
Branches 2024ss
No related tags found
No related merge requests found
Showing
with 340 additions and 0 deletions
/* Copyright (C) 1991-2022 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <libioP.h>
#include <stdarg.h>
#include <stdio.h>
#undef printf
/* Write formatted output to stdout from the format string FORMAT. */
/* VARARGS1 */
int __printf (const char *format, ...) // "const char *format": ANSI-Stil: String-Parameter
{ // "...": ANSI-Stil: Es darf noch weitere Parameter
va_list arg; // geben, die aber nicht geprüft werden.
int done;
va_start (arg, format); // Umwandlung der zusätzlichen Parameter in eine Liste (Array)
done = __vfprintf_internal (stdout, format, arg, 0); // Übergabe an eine Funktion, die
va_end (arg); // die Liste weiterverarbeitet
// --> man vfprintf
return done;
}
#undef _IO_printf
ldbl_strong_alias (__printf, printf); // Name "__printf" wird auf "printf" abgebildet
ldbl_strong_alias (__printf, _IO_printf);
/* Copyright (C) 1991-2022 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <libioP.h>
#include <stdarg.h>
#include <stdio.h>
#undef printf
/* Write formatted output to stdout from the format string FORMAT. */
/* VARARGS1 */
int
__printf (const char *format, ...)
{
va_list arg;
int done;
va_start (arg, format);
done = __vfprintf_internal (stdout, format, arg, 0);
va_end (arg);
return done;
}
#undef _IO_printf
ldbl_strong_alias (__printf, printf);
ldbl_strong_alias (__printf, _IO_printf);
#include <stdio.h>
typedef struct
{
char day;
char month;
int year;
} date;
int main (void)
{
date d = { 5, 7, 2024 };
printf ("Today is %04d-%02d-%02d.\n", d.year, d.month, d.day);
return 0;
}
#include <stdio.h>
typedef struct // Typdefinition
{
char day;
char month;
int year;
} date; // Name des Typs
int main (void)
{
date d = { 5, 7, 2024 }; // Deklaration und Initialisierung einer lokalen Variablen
// "date" = Name des Typs, den wir nutzen, um eine Variable zu deklarieren
// "d" = Name der Variablen
// "= {...}" = Initialisierer
printf ("Today is %04d-%02d-%02d.\n", d.year, d.month, d.day);
return 0;
}
#include <stdio.h>
struct // Deklaration und Initialisierung einer globalen Variablen. Der Datentyp ist anonym.
{
char day;
char month;
int year;
} d // Name der Variablen
= { 5, 7, 2024 }; // Initialisierung
int main (void)
{
printf ("Today is %04d-%02d-%02d.\n", d.year, d.month, d.day);
return 0;
}
#include <stdio.h>
struct // Deklaration und Initialisierung (auf 0) einer globalen Variablen. Der Datentyp ist anonym.
{
char day;
char month;
int year;
} d; // Name der Variablen
// implizite Initialisierung auf 0
int main (void)
{
d = { 5, 7, 2024 };
printf ("Today is %04d-%02d-%02d.\n", d.year, d.month, d.day);
return 0;
}
#include <stdio.h>
struct date // Deklaration und Initialisierung (auf 0) einer globalen Variablen.
{ // Der Datentyp heißt "struct date".
char day;
char month;
int year;
} d; // Name der Variablen
// implizite Initialisierung auf 0
int main (void)
{
struct date tmp = { 5, 7, 2024 };
d = tmp;
printf ("Today is %04d-%02d-%02d.\n", d.year, d.month, d.day);
return 0;
}
#include <stdio.h>
typedef struct date // Typdeklaration.
{ // Der Datentyp heißt sowohl "struct date" (K&R-Stil) als auch "date" (ANSI-Stil).
char day;
char month;
int year;
} date; // Name des Typs, ANSI-Stil
date d; // globale Variable, implizit initialisiert auf 0
int main (void)
{
date tmp = { 5, 7, 2024 }; // Typ wahlweise "struct date" oder "date"
d = tmp;
printf ("Today is %04d-%02d-%02d.\n", d.year, d.month, d.day);
return 0;
}
#include <stdio.h>
typedef struct // Typdeklaration.
{ // Der Datentyp heißt "date" (ANSI-Stil).
char day;
char month;
int year;
} date; // Name des Typs, ANSI-Stil
date d; // globale Variable, implizit initialisiert auf 0
int main (void)
{
date tmp = { 5, 7, 2024 };
d = tmp;
printf ("Today is %04d-%02d-%02d.\n", d.year, d.month, d.day);
return 0;
}
#include <stdio.h>
typedef struct // Typdeklaration.
{ // Der Datentyp heißt "date" (ANSI-Stil).
char day;
char month;
int year;
} date; // Name des Typs, ANSI-Stil
date d; // globale Variable, implizit initialisiert auf 0
int main (void)
{
date tmp; // Nicht initialisiert! ==8-O
d = tmp;
printf ("Today is %04d-%02d-%02d.\n", d.year, d.month, d.day);
return 0;
}
#include <stdio.h>
struct date // Typdeklaration (ANSI-Stil).
{
char day;
char month;
int year;
// Hier könnte man bereits den Datentyp "date" mitverwenden, z.B. für Zeiger.
};
date d; // globale Variable, implizit initialisiert auf 0
int main () // In C++ ist das "void" optional.
{
d = { 5, 7, 2024 }; // Funktioniert das? --> In C++: Ja. :-)
printf ("Today is %04d-%02d-%02d.\n", d.year, d.month, d.day);
return 0;
}
#include <stdio.h>
struct date // Typdeklaration (ANSI-Stil) und gleichzeitig Variablendeklaration.
{
char day;
char month;
int year;
// Hier könnte man bereits den Datentyp "date" mitverwenden, z.B. für Zeiger.
} d; // globale Variable, implizit initialisiert auf 0
int main () // In C++ ist das "void" optional.
{
d = { 5, 7, 2024 }; // Funktioniert das? --> In C++: Ja. :-)
printf ("Today is %04d-%02d-%02d.\n", d.year, d.month, d.day);
return 0;
}
#include <stdio.h>
int main (void)
{
printf ("Hello, world!\n");
return 0;
}
#include <stdio.h>
int main ()
{
printf ("Hello, world!\n");
return 0;
}
#include <stdio.h>
void hello ()
{
printf ("Hello, world!\n");
}
int main ()
{
hello ();
return 0;
}
#include <stdio.h>
void hello ()
{
printf ("Hello, world!\n");
}
int main ()
{
hello ("world");
return 0;
}
#include <stdio.h>
void hello (world) // K&R-Stil: 1 Parameter
char *world;
{
printf ("Hello, %s!\n", world);
}
int main () // K&R-Stil: Parameter der Funktion unbekannt
{
hello ("world");
return 0;
}
#include <stdio.h>
void hello (world) // K&R-Stil: mindestens 1 Parameter
char *world;
{
printf ("Hello, %s!\n", world);
}
int main () // K&R-Stil: Parameter der Funktion unbekannt
{
hello ("world", 42);
return 0;
}
#include <stdio.h>
void hello (world) // K&R-Stil: mindestens 1 Parameter
char *world; // Typ des Parameters
{
printf ("Hello, %s!\n", world);
}
int main () // K&R-Stil: Parameter der Funktion unbekannt
{
hello (42, "world"); // Anzahl der Parameter wird nicht geprüft. Typ erst recht nicht.
return 0;
}
#include <stdio.h>
void hello (world) // K&R-Stil: mindestens 1 Parameter
char *world;
{
printf ("Hello, %s!\n", world);
}
int main () // K&R-Stil: Parameter der Funktion unbekannt
{
hello ();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment