From be246e7ce4e00081ca91ca79534fe5b90a373590 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Thu, 22 Dec 2022 00:52:16 +0100 Subject: [PATCH] move to cmake compile structure --- Makefile | 47 ----------------------- src/abc.c | 27 +++++++++++++ src/adder.c | 9 +++++ src/args.c | 15 ++++++++ src/arrToBin.c | 28 ++++++++++++++ src/ascii.c | 8 ++++ src/calculator.c | 49 ++++++++++++++++++++++++ src/callreference.c | 22 +++++++++++ src/complex.c | 83 ++++++++++++++++++++++++++++++++++++++++ src/dividableBy7.c | 27 +++++++++++++ src/echo.c | 17 ++++++++ src/echochar.c | 8 ++++ src/euler.c | 50 ++++++++++++++++++++++++ src/factorial.c | 39 +++++++++++++++++++ src/fail.c | 10 +++++ src/fread.c | 24 ++++++++++++ src/hello-world.c | 6 +++ src/options.c | 26 +++++++++++++ src/pointer-arithmetic.c | 9 +++++ src/pointermagic.c | 19 +++++++++ src/primenumbers.c | 43 +++++++++++++++++++++ src/quersumme.c | 30 +++++++++++++++ src/readfile.c | 23 +++++++++++ src/redefinition-if.c | 8 ++++ src/redefinition.c | 7 ++++ src/return-specified.c | 15 ++++++++ src/scanf-test.c | 11 ++++++ src/scnaf-hex-test.c | 8 ++++ src/signed-to-unsigned.c | 6 +++ src/sizeofs.c | 10 +++++ src/structdump.c | 42 ++++++++++++++++++++ src/success.c | 10 +++++ src/sum.c | 11 ++++++ src/tabtest.c | 8 ++++ src/umlaut.c | 3 ++ src/unary-double-not.c | 6 +++ src/warning.c | 15 ++++++++ 37 files changed, 732 insertions(+), 47 deletions(-) delete mode 100644 Makefile create mode 100644 src/abc.c create mode 100644 src/adder.c create mode 100644 src/args.c create mode 100644 src/arrToBin.c create mode 100644 src/ascii.c create mode 100644 src/calculator.c create mode 100644 src/callreference.c create mode 100644 src/complex.c create mode 100644 src/dividableBy7.c create mode 100644 src/echo.c create mode 100644 src/echochar.c create mode 100644 src/euler.c create mode 100644 src/factorial.c create mode 100644 src/fail.c create mode 100644 src/fread.c create mode 100644 src/hello-world.c create mode 100644 src/options.c create mode 100644 src/pointer-arithmetic.c create mode 100644 src/pointermagic.c create mode 100644 src/primenumbers.c create mode 100644 src/quersumme.c create mode 100644 src/readfile.c create mode 100644 src/redefinition-if.c create mode 100644 src/redefinition.c create mode 100644 src/return-specified.c create mode 100644 src/scanf-test.c create mode 100644 src/scnaf-hex-test.c create mode 100644 src/signed-to-unsigned.c create mode 100644 src/sizeofs.c create mode 100644 src/structdump.c create mode 100644 src/success.c create mode 100644 src/sum.c create mode 100644 src/tabtest.c create mode 100644 src/umlaut.c create mode 100644 src/unary-double-not.c create mode 100644 src/warning.c diff --git a/Makefile b/Makefile deleted file mode 100644 index 52fda27..0000000 --- a/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -.PHONY = all pre testfiles bigfiles -SOURCES = $(wildcard *.c) -BINARIES = $(SOURCES:%.c=%) -EXECUTABLES= $(addprefix bin/,${BINARIES}) -all: pre $(EXECUTABLES) huffman/bin/huffman testfiles - -big: all bigfiles -pre: - @mkdir -p bin huffman/bin huffman/testfiles - -clean: - rm -rvf bin huffman/testfiles huffman/bin - -huffman/bin/huffman: huffman/huffman.c - $(CC) $(CFLAGS) -o $@ $< -lm - -# TODO convert this phony target into multiple smaller file targets -testfiles: - @dd if=/dev/urandom of=huffman/testfiles/1K-random.img count=1KiB - @dd if=/dev/urandom of=huffman/testfiles/10K-random.img count=10KiB - @dd if=/dev/urandom of=huffman/testfiles/100K-random.img count=100KiB - @dd if=/dev/urandom of=huffman/testfiles/1M-random.img count=1MiB - @dd if=/dev/urandom of=huffman/testfiles/10M-random.img count=10MiB - @dd if=/dev/zero of=huffman/testfiles/1K-zero.img count=1KiB - @dd if=/dev/zero of=huffman/testfiles/10K-zero.img count=10KiB - @dd if=/dev/zero of=huffman/testfiles/100K-zero.img count=100KiB - @dd if=/dev/zero of=huffman/testfiles/1M-zero.img count=1MiB - @dd if=/dev/zero of=huffman/testfiles/10M-zero.img count=10MiB - @echo -e "Wer\ndas\nliest\nist\ndoof\n" > huffman/testfiles/tiny.txt - @yes 'SAFJALJ AF OIAIFOsdp' | head -c 100KB > huffman/testfiles/small.txt - @yes 'lslfkpoipop iipfiasp' | head -c 1MB > huffman/testfiles/mid.txt - - -# TODO convert this phony target into multiple smaller file targets -bigfiles: - @echo "Building some bigger testfiles, this might take a while and draw some performance" - @dd if=/dev/urandom of=huffman/testfiles/100M-random.img count=100MiB - @dd if=/dev/zero of=huffman/testfiles/100M-zero.img count=100MiB - @dd if=/dev/urandom of=huffman/testfiles/1G-random.img count=1GiB - @dd if=/dev/urandom of=huffman/testfiles/10G-random.img count=10GiB - @dd if=/dev/zero of=huffman/testfiles/1G-zero.img count=1GiB - @dd if=/dev/zero of=huffman/testfiles/10G-zero.img count=10GiB - @yes 'a sla d JK J Kkl' | head -c 100MB > huffman/testfiles/big.txt - @yes ' POP OPO )()( as' | head -c 1G > huffman/testfiles/huge.txt - -$(EXECUTABLES): $(SOURCES) - $(CC) $(CFLAGS) -o $@ $< -lm diff --git a/src/abc.c b/src/abc.c new file mode 100644 index 0000000..21e5506 --- /dev/null +++ b/src/abc.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +int main(int argc, char **argv){ + + if(argc<3){ + printf("not enough args! Ex: ./abc 12 -3 5\n"); + exit(EXIT_FAILURE); + } + double a = atoi(argv[1]); + double b = atoi(argv[2]); + double c = atoi(argv[3]); + + printf("(%f)x²+(%f)x+(%f)=0\n", a, b, c); + double l1 = 0, l2 = 0; + double cl1 = 0, cl2 = 0; + l1=(-b + sqrt((b*b)-(4*a*c)))/(2*a); + l2=(-b - sqrt((b*b)-(4*a*c)))/(2*a); + cl1=(-b + csqrt((b*b)-(4*a*c)))/(2*a); + cl2=(-b - csqrt((b*b)-(4*a*c)))/(2*a); + printf("(-%.0f (+-) sqrt[(%.0f²)-(4*%.0f*%.0f)])/2*%.0f\n", b, b, a, c, a); + printf("x1=%f x2=%f\n", l1, l2); + printf("(complex mode)\nx1=%fi\tx2=%fi\n", cl1, cl2); + return 0; +} diff --git a/src/adder.c b/src/adder.c new file mode 100644 index 0000000..f0d22b1 --- /dev/null +++ b/src/adder.c @@ -0,0 +1,9 @@ +#include + +int main() { + int a, b; + printf("Please input two integers to be added.\n"); + scanf("%d %d", &a, &b); + printf("%d + %d = %d\n", a, b, a+b); + return 0; +} diff --git a/src/args.c b/src/args.c new file mode 100644 index 0000000..853554c --- /dev/null +++ b/src/args.c @@ -0,0 +1,15 @@ +#include + +int main(int argc, char* argv[]){ + + if(argc==1){ + printf("Recieved only one argument, idiot"); + return 1; + } + + for(int i = 0; i < argc+1; i++){ + printf("%d. [%s]\n", i+1, argv[i]); + } + + return 0; +} diff --git a/src/arrToBin.c b/src/arrToBin.c new file mode 100644 index 0000000..8fa42bd --- /dev/null +++ b/src/arrToBin.c @@ -0,0 +1,28 @@ +#include +#include + +int main(){ + // input as single int, output as array of ints with only 0 and 1s + + char str_i[20]; + int i; + + fgets(str_i, 20, stdin); + i = strtol(str_i, NULL, 0); + printf("%d", i); + + int bin[16] = { -1 }; + int b; + + printf("[CONTROL]as hex %x\n", i); + for(int j = 16; j>0; j--){ + b = i%2; + i /= 2; + bin[i] = b; + } + for(int j = 0; j < 16; j++){ + printf("%d", bin[j]); + } + printf("\n"); + return 0; +} diff --git a/src/ascii.c b/src/ascii.c new file mode 100644 index 0000000..d0605ef --- /dev/null +++ b/src/ascii.c @@ -0,0 +1,8 @@ +#include + +int main(){ + for(int i=0; i<256; i++){ + printf("(dec)%d\t(hex)0x%02x\t(char)%c\t\n",i,i,i); + } + return 0; +} diff --git a/src/calculator.c b/src/calculator.c new file mode 100644 index 0000000..535710b --- /dev/null +++ b/src/calculator.c @@ -0,0 +1,49 @@ +#include +#include +#include + +double factorial(double i) { + if(i <= 1) { + return 1; + } + return i * factorial(i - 1); +} + +double power(double a, double b) { + double result = a; + for(int i=0;i + +int* ref(int *i, int* j, int* result){ + *result = *i + *j; + return result; +} + +int val(int a, int b){ + return a+b; +} + +int main(){ + + int x = 1000; + int y = 337; + int z; + printf("given: %d\n", x); + printf("reference: %d\n", *ref(&x, &y, &z)); + printf("value: %d\n", val(x, y)); + + return 0; +} diff --git a/src/complex.c b/src/complex.c new file mode 100644 index 0000000..dcd2a52 --- /dev/null +++ b/src/complex.c @@ -0,0 +1,83 @@ +#include + +typedef struct +{ + float real; + float imaginary; +}complex; + +complex assignComplex(){ + float r, i; + scanf("%f", &r); + scanf("%f", &i); + complex c; + c.real = r; + c.imaginary = i; + return c; +} + +void addComplex() { + printf("First complex\n"); + complex a = assignComplex(); + printf("Second complex\n"); + complex b = assignComplex(); + + complex r; + r.real = a.real + b.real; + r.imaginary = a.imaginary + b.imaginary; + printf("Result: %f+%fi\n", r.real, r.imaginary); +} + +void subComplex() { + printf("First complex\n"); + complex a = assignComplex(); + printf("Second complex\n"); + complex b = assignComplex(); + + complex r; + r.real = a.real - b.real; + r.imaginary = a.imaginary - b.imaginary; + printf("Result: %f+%fi\n", r.real, r.imaginary); +} + +void mulComplex() { + printf("First complex\n"); + complex a = assignComplex(); + printf("Second complex\n"); + complex b = assignComplex(); + + complex r; + r.real = a.real * b.real; + r.imaginary = a.imaginary * b.imaginary; + printf("Result: %f+%fi\n", r.real, r.imaginary); +} + +void divComplex() { + printf("First complex\n"); + complex a = assignComplex(); + printf("Second complex\n"); + complex b = assignComplex(); + + complex r; + r.real = a.real / b.real; + r.imaginary = a.imaginary / b.imaginary; + printf("Result: %f+%fi\n", r.real, r.imaginary); +} + +int main() { + printf("Usage:\n\toperations: + - * /\n\tquit: q\n"); + + char in; + while(1){ + + in = getchar(); + switch(in){ + case 'q': return 0; + case '+': addComplex(); break; + case '-': subComplex(); break; + case '*': mulComplex(); break; + case '/': divComplex(); break; + default: printf("kaputt\n"); break; + } + } +} diff --git a/src/dividableBy7.c b/src/dividableBy7.c new file mode 100644 index 0000000..bca2ea4 --- /dev/null +++ b/src/dividableBy7.c @@ -0,0 +1,27 @@ +/* + * lower and upper end as user input + * use a for loop to output all numbers for which 7|x is true. + */ + +#include + +int main() { + + int a,b; + printf("input lower end:\n"); + fflush(stdin); + scanf("%d",&a); + printf("input upper end:\n"); + fflush(stdin); + scanf("%d",&b); + + printf("inputs: %d %d\n", a, b); + for(int i=a; i<=b; i++){ + if(i%7==0) + printf("%d ", i); + if(i==b) + printf("\n"); + } + + return 0; +} diff --git a/src/echo.c b/src/echo.c new file mode 100644 index 0000000..8a35260 --- /dev/null +++ b/src/echo.c @@ -0,0 +1,17 @@ +#include + +int main() { + char s[100]; + //gets(s); + /* + * Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and be‐ + * cause gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break + * computer security. Use fgets() instead. + * + * For more information, see CWE-242 (aka "Use of Inherently Dangerous Function") at http://cwe.mitre.org/data/definitions/242.html + * + */ + fgets(s, sizeof(s), stdin); + printf("%s\n", s); + return 0; +} diff --git a/src/echochar.c b/src/echochar.c new file mode 100644 index 0000000..a2020a9 --- /dev/null +++ b/src/echochar.c @@ -0,0 +1,8 @@ +#include + +int main() { + + char a = getchar(); + printf("%c", a); + return 0; +} diff --git a/src/euler.c b/src/euler.c new file mode 100644 index 0000000..30272da --- /dev/null +++ b/src/euler.c @@ -0,0 +1,50 @@ +#include + +#include +#include + +// range of unsigned long long is: +// 18.446.744.073.709.551.615 +// maximum factorial with this is 65! +// Double goes up to 170! +double factorial(double i) { + + if(i <= 1) { + return 1; + } + return i * factorial(i - 1); +} + + double factorialFor(double given){ + double p = 1; + + // someone said i need 2 for loops. Totally wrong? + for(int j=1;j +#include + +// range of unsigned long long is: +// 18.446.744.073.709.551.615 +// maximum factorial with this is 65! +// Double goes up to 170! +double factorial(double i) { + + if(i <= 1) { + return 1; + } + return i * factorial(i - 1); +} + + double factorialFor(double given){ + double p = 1; + + // someone said i need 2 for loops. Totally wrong? + for(int j=1;j + +/* + * This program has the purpose of returning a -1 value, indicating the shell that something has gone wrong + * while the program was running. + */ + +int main(){ + return -1; +} diff --git a/src/fread.c b/src/fread.c new file mode 100644 index 0000000..15989c7 --- /dev/null +++ b/src/fread.c @@ -0,0 +1,24 @@ +#include +#include + +int main () { + FILE *fp; + char c[] = "this is tutorialspoint"; + char buffer[100]; + + /* Open file for both reading and writing */ + fp = fopen("file.txt", "w+"); + + /* Write data to the file */ + fwrite(c, strlen(c) + 1, 1, fp); + + /* Seek to the beginning of the file */ + fseek(fp, 0, SEEK_SET); + + /* Read and display data */ + fread(buffer, strlen(c)+1, 1, fp); + printf("%s\n", buffer); + fclose(fp); + + return(0); +} diff --git a/src/hello-world.c b/src/hello-world.c new file mode 100644 index 0000000..04ce434 --- /dev/null +++ b/src/hello-world.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello world!\n"); + return 0; +} diff --git a/src/options.c b/src/options.c new file mode 100644 index 0000000..821e50a --- /dev/null +++ b/src/options.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + bool isCaseInsensitive = false; + int opt; + enum { CHARACTER_MODE, WORD_MODE, LINE_MODE } mode = CHARACTER_MODE; + + while ((opt = getopt(argc, argv, "ilw")) != -1) { + switch (opt) { + case 'i': isCaseInsensitive = true; break; + case 'l': mode = LINE_MODE; break; + case 'w': mode = WORD_MODE; break; + default: + fprintf(stderr, "Usage: %s [-ilw] [file...]\n", argv[0]); + exit(EXIT_FAILURE); + } + } + + // Now optind (declared extern int by ) is the index of the first non-option argument. + // If it is >= argc, there were no non-option arguments. + +} diff --git a/src/pointer-arithmetic.c b/src/pointer-arithmetic.c new file mode 100644 index 0000000..1c00204 --- /dev/null +++ b/src/pointer-arithmetic.c @@ -0,0 +1,9 @@ +#include + +int main() { + int a[5] = {22, 33, 44, 55, 66}; + int *ptr = NULL; + ptr = a; /* point to the first array element */ + for(int i = 0; i < 50; i++) { + printf(" value:0x%-10x\tor 0d%-16d\tAdress:%-8x\n", *(ptr+i), *(ptr+i), ptr+i); /* 33 */ +}} diff --git a/src/pointermagic.c b/src/pointermagic.c new file mode 100644 index 0000000..0e9d93e --- /dev/null +++ b/src/pointermagic.c @@ -0,0 +1,19 @@ +#include + +void printLoc(int y) { + printf("Address of y is %x\n", &y); +} + +void printPointerLoc(int *x) { + printf("Adress of x is %x\n", &x); + printf("Adress the x pointer points to is %x\n", x); + printf("Adress of whatever *x is is %x\n", *x); +} + +int main() { + int a = 0xAAAA; + printf("Address of a is %x\n", &a); + printLoc(a); + printPointerLoc(&a); + return 0; +} diff --git a/src/primenumbers.c b/src/primenumbers.c new file mode 100644 index 0000000..2fd7994 --- /dev/null +++ b/src/primenumbers.c @@ -0,0 +1,43 @@ +#include +#include + +int main(int argc, char** argv) { + int maxPrime = atoi(argv[1]); + + int *arr1 = malloc(sizeof(int)*maxPrime); + if(arr1==NULL) + return -1; + for(int i=0; i0)&&(arr1[j]!=p)) + arr1[j]=-1; + } + // get next prime in arr + // FIXME + p = arr1[i]; + for(int l=0;l<512;l++){ + if(p>0) + break; + else { + p = arr1[i+l]; + } + } + for(int l=0;l0) + printf("%d ", arr1[i]); + } + free(arr1); + printf("\n"); + return 0; +} diff --git a/src/quersumme.c b/src/quersumme.c new file mode 100644 index 0000000..7484927 --- /dev/null +++ b/src/quersumme.c @@ -0,0 +1,30 @@ +#include +int main() { + int a, digits = 0, b = 0; + printf("input a number for calculation\n"); + fflush(stdin); + scanf("%d",&a); + + int digit[128]; + + // look out for wrong order + for(int i=0; i<128; i++) { + digit[i] = a % 10; + if(a>0) + a = a / 10; + else { + if(digits==-1) + digits = i; + digit[i] = -1; + } + //printf("%d. digit is: %d\n", i, digit[i]); + } + + // array is in wrong order, but who cares for the quersumme + for(int i=0; i<128; i++){ + if(digit[i]>0) + b += digit[i]; + } + printf("quersumme is: %d\n", b); + return 0; +} diff --git a/src/readfile.c b/src/readfile.c new file mode 100644 index 0000000..fb5f773 --- /dev/null +++ b/src/readfile.c @@ -0,0 +1,23 @@ +#include +#include + +int main(void) +{ + char filename[] = "file.txt"; + char buf[2]; + FILE *fp; + + if ((fp = fopen(filename, "rb")) == NULL) + { + printf("Unable to open file: %s\n", filename); + return EXIT_FAILURE; + } + + if (fread(buf, 1, 2, fp) == 2) + { + printf("%02x %02x\n", (int) buf[0], (int) buf[1]); + } + + fclose(fp); + return 0; +} diff --git a/src/redefinition-if.c b/src/redefinition-if.c new file mode 100644 index 0000000..8c03c48 --- /dev/null +++ b/src/redefinition-if.c @@ -0,0 +1,8 @@ +#include +int main() { + int a; + if(1){ + int a; // works, this a is only in scope of the if statement. + } + return 0; +} diff --git a/src/redefinition.c b/src/redefinition.c new file mode 100644 index 0000000..081dcea --- /dev/null +++ b/src/redefinition.c @@ -0,0 +1,7 @@ +#include +int a = 1; +int main() { + int a = 2; + printf("%d\n", a); // local overrides global + return 0; +} diff --git a/src/return-specified.c b/src/return-specified.c new file mode 100644 index 0000000..7477ffa --- /dev/null +++ b/src/return-specified.c @@ -0,0 +1,15 @@ +#include +#include + +/* + * This program takes the given argument and returns it as an integer. + * It might be useful to test a shell. + */ + +int main(int argc, char** argv){ + if(argc<2){ + printf("No argument given.\n"); + return -1; + } + return atoi(argv[1]); +} diff --git a/src/scanf-test.c b/src/scanf-test.c new file mode 100644 index 0000000..8a489b8 --- /dev/null +++ b/src/scanf-test.c @@ -0,0 +1,11 @@ +#include + +int main() { + int a; + float f; + char s[20]; + printf("input an integer, a float, then a string.\n"); + scanf("%d %f %s", &a, &f, s); + printf("%d %f %s\n", a, f, s); + return 0; +} diff --git a/src/scnaf-hex-test.c b/src/scnaf-hex-test.c new file mode 100644 index 0000000..b9b7fa2 --- /dev/null +++ b/src/scnaf-hex-test.c @@ -0,0 +1,8 @@ +#include + +int main() { + int a; + scanf("%x", &a); + printf("hex: %x dec: %d\n", a, a); + return 0; + } diff --git a/src/signed-to-unsigned.c b/src/signed-to-unsigned.c new file mode 100644 index 0000000..9f461a7 --- /dev/null +++ b/src/signed-to-unsigned.c @@ -0,0 +1,6 @@ +#include + +int main() { + signed int a = -1; + printf("%u\n",a); // no need to type cast. %u interprets given bytes of type unsigned int regardless of the datatype. truly low level + } diff --git a/src/sizeofs.c b/src/sizeofs.c new file mode 100644 index 0000000..4a33c01 --- /dev/null +++ b/src/sizeofs.c @@ -0,0 +1,10 @@ +#include + +int main() { + printf("int: %ld \n", sizeof(int)); + printf("float: %ld \n", sizeof(float)); + printf("double: %ld \n", sizeof(double)); + printf("char: %ld \n", sizeof(char)); + + return 0; +} diff --git a/src/structdump.c b/src/structdump.c new file mode 100644 index 0000000..d8cea6b --- /dev/null +++ b/src/structdump.c @@ -0,0 +1,42 @@ +#include +#include +#include + +struct a { + int a; + char str[30]; +}; + +/* + * give an argument to keep the file /tmp/structdump + * like this: bin/dump aaa + */ + +int main(int argc, char** argv){ + struct a* mystruct = malloc(sizeof(struct a)); + if(mystruct == NULL){ + printf("malloc for 1st struct failed!\n"); + return 1; + } + mystruct->a = 12; + char s[30] = "Wer das liest ist doof"; + strcpy(mystruct->str, s); + FILE* fptr = fopen("/tmp/structdump", "wb"); + fwrite(mystruct, sizeof(struct a), 1, fptr); + fclose(fptr); + free(mystruct); + + fptr = fopen("/tmp/structdump", "rb"); + mystruct = malloc(sizeof(struct a)); + if(mystruct == NULL){ + printf("malloc for 2nd struct failed!\n"); + return 1; + } + fread(mystruct, sizeof(struct a), 1, fptr); + printf("mystruct->a: %d\nmystruct->str: \"%s\"\n", mystruct->a, mystruct->str); // SIGSEV + free(mystruct); + fclose(fptr); + if(argc<2) + remove("/tmp/structdump"); + return 0; +} diff --git a/src/success.c b/src/success.c new file mode 100644 index 0000000..4278030 --- /dev/null +++ b/src/success.c @@ -0,0 +1,10 @@ +#include + +/* + * This program has the purpose of returning a 0 value, indicating to the shell that the program was + * executed successfully. + */ + +int main(){ + return 0; +} diff --git a/src/sum.c b/src/sum.c new file mode 100644 index 0000000..75126f5 --- /dev/null +++ b/src/sum.c @@ -0,0 +1,11 @@ +#include + +int main(){ + + int result = 0; + for (int i = 1; i < 101; i++){ + result+=i; + } + printf("sum of 1 up to 100 is: %d\n", result); + return 0; +} diff --git a/src/tabtest.c b/src/tabtest.c new file mode 100644 index 0000000..7902237 --- /dev/null +++ b/src/tabtest.c @@ -0,0 +1,8 @@ +#include + +int main() { + printf("horizontal\ttab\n"); + printf("vertical%ctab\n", 11); + printf("reference line\n"); + return 0; +} diff --git a/src/umlaut.c b/src/umlaut.c new file mode 100644 index 0000000..bbdb9d3 --- /dev/null +++ b/src/umlaut.c @@ -0,0 +1,3 @@ +#include +int main() { return 0; } +int zähler() { return 0; } // umlaute is an unknown char for gcc diff --git a/src/unary-double-not.c b/src/unary-double-not.c new file mode 100644 index 0000000..a611f37 --- /dev/null +++ b/src/unary-double-not.c @@ -0,0 +1,6 @@ +#include + +int main(){ + printf("%d\n",!!42); + return 0; +} diff --git a/src/warning.c b/src/warning.c new file mode 100644 index 0000000..06373c6 --- /dev/null +++ b/src/warning.c @@ -0,0 +1,15 @@ +#include + +int main(){ + char s[2]; + /* + * The following line of code is unsafe. It writes up to 10 bytes into the char array 's', which is only + * 2 Bytes big. A Buffer Overflow can happen. I have chosen to keep that line, because i wanted a source + * file that produces a compiler warning when it is compiled. That is the true purpose of this file. + * + * a safe alternative would be: fgets(s, 2, stdin); + */ + fgets(s, 10, stdin); // UNSAFE + printf("%s\n",s); + return 0; +}