diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/comprun.sh b/comprun.sh index a0b89e3..6f88c82 100755 --- a/comprun.sh +++ b/comprun.sh @@ -1,4 +1,4 @@ #!/bin/sh -gcc main.c lib/*.c +gcc -g main.c lib/*.c ./a.out diff --git a/dap.el b/dap.el new file mode 100644 index 0000000..3ac8d01 --- /dev/null +++ b/dap.el @@ -0,0 +1,18 @@ +;; Eval Buffer with `M-x eval-buffer' to register the newly created template. + +(dap-register-debug-template + "LLDB::Run launch" + (list :type "lldb-vscode" + :cwd "/home/cspark/Documents/C" + :request "launch" + :program "a.out" + :stopOnEntry 'nil + :name "LLDB::Run launch")) + +(dap-register-debug-template + "LLDB::Run connect" + (list :type "lldb-vscode" + :request "attach" + :program "a.out" + :stopAtEntry 'nil + :name "LLDB::Run connect")) diff --git a/lib/array.c b/lib/array.c old mode 100644 new mode 100755 index c93dea3..223c8c1 --- a/lib/array.c +++ b/lib/array.c @@ -1,4 +1,5 @@ #include +#include "array.h" #include "base10.h" int sizeofStr(char in[]) { @@ -21,12 +22,12 @@ void printStrArray(char in[]) { } } -void printIntArray(int in[], int inLength) { +void printIntArray(intArray *in) { int i; printf("{ "); - for (i = 0; i < inLength; ++i) { - printf("%d", in[i]); - if (i == inLength - 1) { + for (i = 0; i < in->length; ++i) { + printf("%d", in->data[i]); + if (i == in->length - 1) { printf(" }\n"); } else { printf(", "); @@ -34,10 +35,10 @@ void printIntArray(int in[], int inLength) { } } -int checkIntArraySorted(int in[], int inLength) { +int checkIntArraySorted(intArray *in) { int i = 0; - while(i < inLength - 1) { - if (in[i] > in[i + 1]) + while(i < in->length - 1) { + if (in->data[i] > in->data[i + 1]) return 0; ++i; } @@ -46,25 +47,28 @@ int checkIntArraySorted(int in[], int inLength) { } /* Convert an integer array into a combined integer */ -int intArrayToInt(int in[], int inLength) { +int intArrayToInt(intArray *in) { int i; int out = 0; - int currentDigit = inLength; - for (i = 1; i <= inLength; ++i) { - out += in[i - 1] * intDigitExpand(currentDigit); - --currentDigit; - } + int currentDigit; + for (i = 0, currentDigit = in->length; i <= in->length; ++i, --currentDigit) + out += in->data[i] * intDigitExpand(currentDigit); return out; } /* Split an integer into an integer array */ -void intToIntArray(int in, int out[]) { +intArray intToIntArray(int in) { + int inLength = intDigitCount(in); + int outData[inLength]; + intArray out; + out.data = outData; + out.length = inLength; int i; - int j = 0; - int currentDigit; - for(i = intDigitCount(in); i >= 1; --i) { - out[j] = in / intDigitExpand(i); - in -= intDigitExpand(i) * out[j]; - ++j; + int j; + for(i = inLength, j = 0; i >= 1; --i, ++j) { + out.data[j] = in / intDigitExpand(i); + in -= intDigitExpand(i) * out.data[j]; } + + return out; } diff --git a/lib/array.h b/lib/array.h old mode 100644 new mode 100755 index f08aa44..cd661a8 --- a/lib/array.h +++ b/lib/array.h @@ -1,16 +1,21 @@ #ifndef ARRAY_H #define ARRAY_H +typedef struct IntArray { + unsigned int length; + int *data; +} intArray; + int sizeofStr(char in[]); void printStrArray(char in[]); -void printIntArray(int in[], int inLength); +void printIntArray(intArray *in); -int checkIntArraySorted(int in[], int inLength); +int checkIntArraySorted(intArray *in); -void intToIntArray(int in, int out[]); +intArray intToIntArray(int in); -int intArrayToInt(int in[], int inLength); +int intArrayToInt(intArray *in); #endif diff --git a/lib/base10.c b/lib/base10.c old mode 100644 new mode 100755 diff --git a/lib/base10.h b/lib/base10.h old mode 100644 new mode 100755 diff --git a/lib/math.c b/lib/math.c new file mode 100644 index 0000000..a703b07 --- /dev/null +++ b/lib/math.c @@ -0,0 +1,16 @@ +#include "array.h" + +intArray findDivisors(int in) { + int i; + intArray out; + for (i = 1; i <= in; ++i) { + if (in % i == 0) { + + } + } + + //out.data = outData; + //out.length = inLength; + + return out; +}; diff --git a/lib/math.h b/lib/math.h new file mode 100644 index 0000000..f474313 --- /dev/null +++ b/lib/math.h @@ -0,0 +1,8 @@ +#ifndef MATH_H +#define MATH_H + +#include "array.h" + +intArray findDivisors(); + +#endif diff --git a/lib/temperature.c b/lib/temperature.c old mode 100644 new mode 100755 diff --git a/lib/temperature.h b/lib/temperature.h old mode 100644 new mode 100755 diff --git a/main.c b/main.c old mode 100644 new mode 100755 index 1886753..8d7cc3b --- a/main.c +++ b/main.c @@ -2,27 +2,44 @@ #include "lib/temperature.h" #include "lib/array.h" #include "lib/base10.h" +// #include "lib/math.h" void swapInt(int *pX, int *pY) { - int temp = *pX; - *pX = *pY; - *pY = temp; + int temp = *pX; + *pX = *pY; + *pY = temp; } +#define ALLOCSIZE 10000 +char allocbuff[ALLOCSIZE]; +char* allocp = allocbuff; +char* alloc(int n) { + if (allocbuff + ALLOCSIZE - allocp >= n) { + allocp += n; + return allocp - n; + } else + return 0; +} int main() { - int unsortedArray[] = { 1, 5, 2, 1, 4, 8, 3, 2, 6, 7 }; - int sortedArray[] = { 1, 2, 4, 8, 9, 9, 9 }; - - printf("Unsorted Array : "); - printIntArray(unsortedArray, sizeof(unsortedArray) / sizeof(int)); - printf("Unsorted Array Sorted?: %d\n", checkIntArraySorted(unsortedArray, sizeof(unsortedArray) / sizeof(int))); - printf("Sorted Array : "); - printIntArray(sortedArray, sizeof(sortedArray) / sizeof(int)); - printf("Sorted Array Sorted?: %d\n", checkIntArraySorted(sortedArray, sizeof(sortedArray) / sizeof(int))); - - printf("40C == %dF", (int) celsiusToFarenheit(40.0)); - + + intArray unsortedArray; + int unsortedArrayData[] = { 1, 5, 2, 1, 4, 8, 3, 2, 6, 7 }; + unsortedArray.length = sizeof(unsortedArrayData) / sizeof(int); + unsortedArray.data = unsortedArrayData; + intArray sortedArray; + int sortedArrayData[] = { 1, 2, 4, 8, 9, 9, 9 }; + sortedArray.length = sizeof(sortedArrayData) / sizeof(int); + sortedArray.data = sortedArrayData; + + printf("Unsorted Array : "); + printIntArray(&unsortedArray); + printf("Unsorted Array Sorted?: %d\n", checkIntArraySorted(&unsortedArray)); + printf("Sorted Array : "); + printIntArray(&sortedArray); + printf("Sorted Array Sorted?: %d\n", checkIntArraySorted(&sortedArray)); + + printf("40C == %dF\n", (int) celsiusToFarenheit(40.0)); }