Initial commit

This commit is contained in:
2021-10-01 20:24:05 +02:00
commit 860c025165
194 changed files with 4846 additions and 0 deletions

11
kapitel15/exempel.c Normal file
View File

@@ -0,0 +1,11 @@
#include <stdio.h>
int main(void)
{
int x, y;
x = 5;
printf("x = %d\n", x);
printf("Adressen till x är %lu\n", &x);
return 0;
}

4
kapitel15/funk.c Normal file
View File

@@ -0,0 +1,4 @@
int kvadrat(int n)
{
return n*n;
}

1
kapitel15/funk.h Normal file
View File

@@ -0,0 +1 @@
int kvadrat(int n);

10
kapitel15/jbmath/jbmath.c Normal file
View File

@@ -0,0 +1,10 @@
float circumf(float diameter)
{
const float pi = 3.14159265;
return (pi * diameter);
}
float area(float length, float height)
{
return (length * height);
}

View File

@@ -0,0 +1,3 @@
float circumf(float diameter);
float area(float length, float height);
long jbpow(int x, int n);

10
kapitel15/jbmath/jbpow.c Normal file
View File

@@ -0,0 +1,10 @@
long jbpow(int x, int n)
{
long num = 1;
int i;
for(i = 0; i<n; i++)
{
num = num * x;
}
return num;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <jbmath.h>
int main(void)
{
printf("En cirkel med diametern 5.5 har omkretsen %.3f\n",
circumf(5.5));
printf("En rektangel med sidorna 3 och 8.5 har arean %.3f\n",
area(3, 8.5));
printf("5 upphöjt till 6 är %ld\n", jbpow(5, 6));
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include "jbmath.h"
int main(void)
{
printf("En cirkel med diametern 5.5 har omkretsen %.3f\n",
circumf(5.5));
printf("En rektangel med sidorna 3 och 8.5 har arean %.3f\n",
area(3, 8.5));
printf("5 upphöjt till 6 är %ld\n", jbpow(5, 6));
return 0;
}

17
kapitel15/matte/Makefile Normal file
View File

@@ -0,0 +1,17 @@
CC=cc
CFLAGS=-Wall -Wextra -pedantic -std=c99 -D_XOPEN_SOURCE=600
matte: matte.o minmattefunk.o usage.o
$(CC) -o matte matte.o minmattefunk.o usage.o
matte.o: matte.c minmattefunk.h usage.h
$(CC) $(CFLAGS) -c matte.c
minmattefunk.o: minmattefunk.c
$(CC) $(CFLAGS) -c minmattefunk.c
usage.o: usage.c
$(CC) $(CFLAGS) -c usage.c
clean:
rm matte minmattefunk.o matte.o usage.o

34
kapitel15/matte/matte.c Normal file
View File

@@ -0,0 +1,34 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "minmattefunk.h"
#include "usage.h"
int main(int argc, char **argv)
{
int opt;
if (argc == 1)
{
printUsage(argv[0]);
return 1;
}
while ((opt = getopt(argc, argv, "s:c:")) != -1)
{
switch (opt)
{
case 's':
printf("%d squared is %d\n", atoi(optarg),
kvadrat(atoi(optarg)));
break;
case 'c':
printf("%d cubed is %d \n", atoi(optarg),
kubik(atoi(optarg)));
break;
default:
printUsage(argv[0]);
return 1;
}
}
return 0;
}

View File

@@ -0,0 +1,9 @@
int kvadrat(int x)
{
return x*x;
}
int kubik(int x)
{
return x*x*x;
}

View File

@@ -0,0 +1,2 @@
int kvadrat(int x);
int kubik(int x);

8
kapitel15/matte/usage.c Normal file
View File

@@ -0,0 +1,8 @@
#include <stdio.h>
void printUsage(char *arg)
{
printf("Usage: %s (-s) | (-c) (integer)\n"
"-s = calculate the square of an integer\n"
"-c = calculate the cube of an integer\n", arg);
}

1
kapitel15/matte/usage.h Normal file
View File

@@ -0,0 +1 @@
void printUsage(char *arg);

View File

@@ -0,0 +1,10 @@
CC=cc
CFLAGS=-Wall -Wextra -pedantic -std=c99 -D_XOPEN_SOURCE=600
matte: matte.o minmattefunk.o usage.o
$(CC) -o matte matte.o minmattefunk.o usage.o
matte.o: minmattefunk.h usage.h
clean:
rm matte minmattefunk.o matte.o usage.o

View File

@@ -0,0 +1,11 @@
CC=cc
CFLAGS=-Wall -Wextra -pedantic -std=c99 -D_XOPEN_SOURCE=600
OBJS=matte.o minmattefunk.o usage.o
matte: $(OBJS)
$(CC) -o matte $(OBJS)
matte.o: minmattefunk.h usage.h
clean:
rm matte $(OBJS)

View File

@@ -0,0 +1,18 @@
CC=cc
CFLAGS=-Wall -Wextra -pedantic -std=c99 -D_XOPEN_SOURCE=600
OBJS=matte.o minmattefunk.o usage.o
PREFIX=/usr/local
matte: $(OBJS)
$(CC) -o matte $(OBJS)
matte.o: minmattefunk.h usage.h
clean:
rm matte $(OBJS)
install:
cp matte $(DESTDIR)$(PREFIX)/bin/matte
uninstall:
rm $(DESTDIR)$(PREFIX)/bin/matte

7
kapitel15/prog.c Normal file
View File

@@ -0,0 +1,7 @@
#include "funk.h"
#define TAL 8
int main(void)
{
return kvadrat(TAL);
}