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

Beispiele und Screenshots 7.11.2024

parent 6a82493d
No related branches found
No related tags found
No related merge requests found
Showing
with 288 additions and 0 deletions
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/20241107> gcc -Wall -O3 files-01.c -o files-01
cassini/home/peter/bo/2024ws/hp/20241107> ./files-01
cassini/home/peter/bo/2024ws/hp/20241107> cat fhello.txt
Hello, world!
cassini/home/peter/bo/2024ws/hp/20241107> ls -l fhello.txt
-rw-r--r-- 1 peter peter 14 7. Nov 12:40 fhello.txt
cassini/home/peter/bo/2024ws/hp/20241107> chmod 000 fhello.txt
cassini/home/peter/bo/2024ws/hp/20241107> ls -l fhello.txt
---------- 1 peter peter 14 7. Nov 12:40 fhello.txt
cassini/home/peter/bo/2024ws/hp/20241107> ./files-01
Speicherzugriffsfehler
cassini/home/peter/bo/2024ws/hp/20241107>
#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
printf ("Fehler!\n");
return 0;
}
#include <stdio.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f)
{
fprintf (f, "Hello, world!\n");
fclose (f);
return 0;
}
else
{
fprintf (stderr, "Fehler!\n");
return 1;
}
}
#include <stdio.h>
#include <errno.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f)
{
fprintf (f, "Hello, world!\n");
fclose (f);
return 0;
}
else
{
fprintf (stderr, "Fehler Nr. %d!\n", errno);
return 1;
}
}
#include <stdio.h>
#include <errno.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f)
{
fprintf (f, "Hello, world!\n");
fclose (f);
return 0;
}
else
{
fprintf (stderr, "err#%d!\n", errno);
return 1;
}
}
#include <stdio.h>
#include <errno.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (f)
{
fprintf (f, "Hello, world!\n");
fclose (f);
return 0;
}
else
{
fprintf (stderr, "err#%d!\n", errno);
return errno;
}
}
#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, "%s\n", msg);
return errno;
}
}
#include <stdio.h>
#include <errno.h>
#include <error.h>
int main (void)
{
FILE *f = fopen ("fhello.txt", "w");
if (!f)
error (errno, errno, "cannot open file");
fprintf (f, "Hello, world!\n");
fclose (f);
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;
}
#include <stdio.h>
int main (int argc, char **argv)
{
printf ("argc = %d\n", argc);
for (int i = 0; argv[i]; 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);
int i = 0;
while (*argv)
printf ("argv[%d] = \"%s\"\n", i++, *argv++);
return 0;
}
#include <stdio.h>
#include <string.h>
int main (void)
{
char hello[] = "Hello, world!\n";
printf ("%s\n", hello);
printf ("%zd\n", strlen (hello));
return 0;
printf ("%s\n", hello + 7);
printf ("%zd\n", strlen (hello + 7));
hello[5] = 0;
printf ("%s\n", hello);
printf ("%zd\n", strlen (hello));
return 0;
}
#include <stdio.h>
#include <string.h>
int main (void)
{
char hello[] = "Hello, world!\n";
printf ("%s\n", hello);
printf ("%zd\n", strlen (hello));
printf ("%s\n", hello + 7);
printf ("%zd\n", strlen (hello + 7));
return 0;
hello[5] = 0;
printf ("%s\n", hello);
printf ("%zd\n", strlen (hello));
return 0;
}
#include <stdio.h>
#include <string.h>
int main (void)
{
char hello[] = "Hello, world!\n";
printf ("%s\n", hello);
printf ("%zd\n", strlen (hello));
printf ("%s\n", hello + 7);
printf ("%zd\n", strlen (hello + 7));
hello[5] = 0;
printf ("%s\n", hello);
printf ("%zd\n", strlen (hello));
return 0;
}
#include <stdio.h>
#include <string.h>
int main (void)
{
char hello[] = "Hello, world!\n";
printf ("%s\n", hello);
printf ("%zd\n", strlen (hello));
printf ("%s\n", hello + 7);
printf ("%zd\n", strlen (hello + 7));
hello[5] = 0;
printf ("%s\n", hello);
printf ("%zd\n", strlen (hello));
printf ("%s\n", hello + 6);
printf ("%zd\n", strlen (hello + 6));
return 0;
}
#include <stdio.h>
int main (void)
{
char *hello = "Hello, world!\n";
printf ("%s", p);
return 0;
}
#include <stdio.h>
int main (void)
{
char *hello = "Hello, world!\n";
printf ("%s", *p);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment