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

weitere Beispiele und Screenshot 14.11.2024

parent c115a152
Branches
No related tags found
No related merge requests found
Showing
with 278 additions and 0 deletions
#include <stdio.h>
int main (void)
{
printf ("Der ASCII-Wert von %c lautet: %d\n", '*', '*');
char ch = 'M';
if (ch >= 'A' && ch <= 'Z')
{
printf ("Der Buchstabe %c ist ein Großbuchstabe.\n", ch);
ch += 'a' - 'A';
printf ("Der zugehörige Kleinbuchstabe lautet: %c\n", ch);
}
return 0;
}
Hello, world!
#include <stdio.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
fprintf (f, "Hello, world!\n");
fclose (f);
return 0;
}
#include <stdio.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
fprintf (f, "Hello, world!\n");
fclose (f);
return 0;
}
cassini/home/peter/bo/2024ws/hp/20241114> gcc -Wall -O files-01.c -o files-01
cassini/home/peter/bo/2024ws/hp/20241114> ./files-01
cassini/home/peter/bo/2024ws/hp/20241114> cat fhello.txt
Hello, world!
cassini/home/peter/bo/2024ws/hp/20241114> ls -l fhello.txt
-rw-r--r-- 1 peter peter 14 14. Nov 11:57 fhello.txt
cassini/home/peter/bo/2024ws/hp/20241114> chmod 400 fhello.txt
cassini/home/peter/bo/2024ws/hp/20241114> ls -l fhello.txt
-r-------- 1 peter peter 14 14. Nov 11:57 fhello.txt
cassini/home/peter/bo/2024ws/hp/20241114> ./files-01
Speicherzugriffsfehler
cassini/home/peter/bo/2024ws/hp/20241114>
#include <stdio.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f)
{
fprintf (f, "Hello, world!\n");
fclose (f);
}
return 0;
}
#include <stdio.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f)
{
fprintf (f, "Hello, world!\n");
fclose (f);
}
else
fprintf (stderr, "Fehler!\n");
return 0;
}
#include <stdio.h>
#include <errno.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f)
{
fprintf (f, "Hello, world!\n");
fclose (f);
}
else
fprintf (stderr, "err #%d\n", errno);
return 0;
}
#include <stdio.h>
#include <errno.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f)
{
fprintf (f, "Hello, world!\n");
fclose (f);
}
else
fprintf (stderr, "err #%s\n", errno);
return 0;
}
#include <stdio.h>
#include <errno.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f)
{
fprintf (f, "Hello, world!\n");
fclose (f);
}
else
fprintf (stderr, "err #%c\n", errno);
return 0;
}
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f)
{
fprintf (f, "Hello, world!\n");
fclose (f);
}
else
{
char *msg = strerror (errno);
fprintf (stderr, "error #%d: %s\n", errno, msg);
}
return 0;
}
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f)
{
fprintf (f, "Hello, world!\n");
fclose (f);
return 0;
}
else
{
char *msg = strerror (errno);
fprintf (stderr, "error #%d: %s\n", errno, msg);
return errno;
}
}
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f == NULL)
{
char *msg = strerror (errno);
fprintf (stderr, "error #%d: %s\n", errno, msg);
return errno;
}
fprintf (f, "Hello, world!\n");
fclose (f);
return 0;
}
#include <stdio.h>
#include <errno.h>
#include <error.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f == NULL)
error (errno, errno, "cannot open file");
fprintf (f, "Hello, world!\n");
fclose (f);
return 0;
}
#include <stdio.h>
int main (void)
{
printf ("Hello, world!\n");
return 0;
}
extern int printf (const char *__restrict __format, ...);
int main (void)
{
printf ("Hello, world!\n");
return 0;
}
cassini/home/peter/bo/2024ws/hp/20241114> cat maerchen.c
Vor langer, langer Zeit
gab es einmal
#include "hexe.h"
Die lebte in einem Wald.
cassini/home/peter/bo/2024ws/hp/20241114> cat hexe.h
eine kleine Hexe.
cassini/home/peter/bo/2024ws/hp/20241114> gcc -Wall -O3 maerchen.c -o maerchen
maerchen.c:1:1: error: unknown type name ‘Vor’
1 | Vor langer, langer Zeit
| ^~~
maerchen.c:1:20: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Zeit’
1 | Vor langer, langer Zeit
| ^~~~
cassini/home/peter/bo/2024ws/hp/20241114> gcc -Wall -O3 maerchen.c -E
# 0 "maerchen.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "maerchen.c"
Vor langer, langer Zeit
gab es einmal
# 1 "hexe.h" 1
eine kleine Hexe.
# 4 "maerchen.c" 2
Die lebte in einem Wald.
cassini/home/peter/bo/2024ws/hp/20241114> gcc -Wall -O3 maerchen.c -E -P
Vor langer, langer Zeit
gab es einmal
eine kleine Hexe.
Die lebte in einem Wald.
cassini/home/peter/bo/2024ws/hp/20241114>
#include <stdio.h>
int main (int argc, char **argv)
{
printf ("argc = %d\n", argc);
for (int i = 0; i < argc; i++)
printf ("argv[%d] = \"%s\"\n", i, argv[i]);
return 0;
}
#include <stdio.h>
int main (int argc, char **argv)
{
printf ("argc = %d\n", argc);
for (int i = 0; i < argc; i++)
printf ("argv[%d] = \"%s\"\n", i, argv[i]);
return 0;
}
cassini/home/peter/bo/2024ws/hp/20241114> gcc -Wall -O3 main-params-01.c -o main-params-01 cassini/home/peter/bo/2024ws/hp/20241114> ./main-params-01
argc = 1
argv[0] = "./main-params-01"
cassini/home/peter/bo/2024ws/hp/20241114> ./main-params-01 foo bar baz
argc = 4
argv[0] = "./main-params-01"
argv[1] = "foo"
argv[2] = "bar"
argv[3] = "baz"
cassini/home/peter/bo/2024ws/hp/20241114>
#include <stdio.h>
int main (int argc, char **argv)
{
printf ("argc = %d\n", argc);
for (int i = 0; argv[i] != NULL; i++)
printf ("argv[%d] = \"%s\"\n", i, argv[i]);
return 0;
}
#include <stdio.h>
int main (int argc, char **argv)
{
for (char *p = argv; *p; p++)
printf ("\"%s\"\n", *p);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment