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

Beispielprogramme 13.11.2017

parent 1a44c250
No related branches found
No related tags found
No related merge requests found
Showing with 202 additions and 3 deletions
No preview for this file type
......@@ -20,7 +20,7 @@
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
% README: Parameter des Hauptprogramms, String-Operationen, Präprozessor-Macros, make, Bit-Operationen, I/O-Ports
% README: Parameter des Hauptprogramms, String-Operationen, Präprozessor-Macros, make
\documentclass[10pt,t]{beamer}
......@@ -466,7 +466,7 @@
CFLAGS = -Wall -O
$(TARGET): $(OBJECTS)
gcc $(OBJECTS) -o philosophy
gcc $(OBJECTS) -o $(TARGET)
%.o: %.c $(HEADERS)
gcc $(CFLAGS) $< -c
......@@ -486,7 +486,7 @@
CFLAGS = -Wall -O
$(TARGET): $(OBJECTS)
gcc $(OBJECTS) -o philosophy
gcc $(OBJECTS) -o $(TARGET)
answer.o: answer.c $(HEADERS)
gcc $(CFLAGS) answer.c -c
......
#include <stdio.h>
#define VIER 4
int main (void)
{
printf ("%d\n", VIER);
return 0;
}
#include <stdio.h>
#define VIER 4;
int main (void)
{
printf ("%d\n", VIER);
return 0;
}
#include <stdio.h>
#define VIER 2 + 2
int main (void)
{
printf ("%d\n", VIER);
return 0;
}
#include <stdio.h>
#define VIER 2 + 2
int main (void)
{
printf ("3 * 4 = %d\n", 3 * VIER);
return 0;
}
#include <stdio.h>
#define VIER (2 + 2)
int main (void)
{
printf ("3 * 4 = %d\n", 3 * VIER);
return 0;
}
#include <stdio.h>
int main (int argc, char **argv)
{
printf ("argc = %d\n", argc);
return 0;
}
#include <stdio.h>
int main (int argc, char **argv)
{
printf ("argc = %d\n", argc);
printf ("**argv = %c\n", **argv);
return 0;
}
#include <stdio.h>
int main (int argc, char **argv)
{
printf ("argc = %d\n", argc);
printf ("*argv = %s\n", *argv);
return 0;
}
#include <stdio.h>
int main (int argc, char **argv)
{
printf ("argc = %d\n", argc);
printf ("argv[0] = %s\n", argv[0]);
return 0;
}
#include <stdio.h>
int main (int argc, char **argv)
{
printf ("argc = %d\n", argc);
for (int i = 0; i < 4; 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;
}
#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>
#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 buffer[100] = "";
sprintf (buffer, "Die Antwort lautet: %d. Das war eine tolle Antwort.", 42);
printf ("%s\n", buffer);
char *answer = strstr (buffer, "Antwort");
printf ("%s\n", answer);
answer = strstr (answer + 1, "Antwort");
printf ("%s\n", answer);
printf ("found at: %zd\n", answer - buffer);
return 0;
}
#include <stdio.h>
#include <string.h>
int main (void)
{
char *anton = "Anton";
char *zacharias = "Zacharias";
printf ("%d\n", strcmp (anton, zacharias));
printf ("%d\n", strcmp (zacharias, anton));
printf ("%d\n", strcmp (anton, anton));
char buffer[100] = "Huber ";
strcat (buffer, anton);
printf ("%s\n", buffer);
return 0;
}
#include <stdio.h>
#include <string.h>
int main (void)
{
char *anton = "Anton";
if (!strcmp (anton, "Anton"))
printf ("Die Strings sind gleich.\n");
else
printf ("Die Strings sind ungleich.\n");
return 0;
}
#include <stdio.h>
#include <string.h>
int main (void)
{
char *anton = "Anton";
if (strcmp (anton, "Anton") == 0)
printf ("Die Strings sind gleich.\n");
else
printf ("Die Strings sind ungleich.\n");
return 0;
}
#include <stdio.h>
#include <string.h>
int main (void)
{
char *anton = "Anton";
char *zacharias = "Zacharias";
printf ("%d\n", strcmp (anton, zacharias));
printf ("%d\n", strcmp (zacharias, anton));
printf ("%d\n", strcmp (anton, anton));
char buffer[] = "Huber ";
strcat (buffer, anton);
printf ("%s\n", buffer);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment