diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 20b73d1..0000000 --- a/.clang-format +++ /dev/null @@ -1,322 +0,0 @@ ---- -Language: Cpp -BasedOnStyle: LLVM -AlignAfterOpenBracket: true -AccessModifierOffset: -2 -AlignArrayOfStructures: None -AlignConsecutiveAssignments: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: true -AlignConsecutiveBitFields: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveDeclarations: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: true - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveMacros: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveShortCaseStatements: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCaseArrows: false - AlignCaseColons: false -AlignConsecutiveTableGenBreakingDAGArgColons: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveTableGenCondOperatorColons: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveTableGenDefinitionColons: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionDeclarations: false - AlignFunctionPointers: false - PadOperators: false -AlignEscapedNewlines: Right -AlignOperands: Align -AlignTrailingComments: - AlignPPAndNotPP: true - Kind: Always - OverEmptyLines: 0 -AllowAllArgumentsOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowBreakBeforeNoexceptSpecifier: Never -AllowBreakBeforeQtProperty: false -AllowShortBlocksOnASingleLine: Never -AllowShortCaseExpressionOnASingleLine: true -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: true -AllowShortEnumsOnASingleLine: true -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: Never -AllowShortLambdasOnASingleLine: All -AllowShortLoopsOnASingleLine: false -AllowShortNamespacesOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AttributeMacros: - - __capability -BinPackArguments: true -BinPackLongBracedList: true -BinPackParameters: BinPack -BitFieldColonSpacing: Both -BracedInitializerIndentWidth: -1 -BraceWrapping: - AfterCaseLabel: false - AfterClass: false - AfterControlStatement: Never - AfterEnum: false - AfterExternBlock: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakAdjacentStringLiterals: true -BreakAfterAttributes: Leave -BreakAfterJavaFieldAnnotations: false -BreakAfterOpenBracketBracedList: false -BreakAfterOpenBracketFunction: false -BreakAfterOpenBracketIf: false -BreakAfterOpenBracketLoop: false -BreakAfterOpenBracketSwitch: false -BreakAfterReturnType: None -BreakArrays: true -BreakBeforeBinaryOperators: None -BreakBeforeCloseBracketBracedList: false -BreakBeforeCloseBracketFunction: false -BreakBeforeCloseBracketIf: false -BreakBeforeCloseBracketLoop: false -BreakBeforeCloseBracketSwitch: false -BreakBeforeConceptDeclarations: Always -BreakBeforeBraces: Attach -BreakBeforeInlineASMColon: OnlyMultiline -BreakBeforeTemplateCloser: false -BreakBeforeTernaryOperators: true -BreakBinaryOperations: Never -BreakConstructorInitializers: BeforeColon -BreakFunctionDefinitionParameters: false -BreakInheritanceList: BeforeColon -BreakStringLiterals: true -BreakTemplateDeclarations: MultiLine -ColumnLimit: 0 -CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: AlignFirstComment -DerivePointerAlignment: false -DisableFormat: false -EmptyLineAfterAccessModifier: Never -EmptyLineBeforeAccessModifier: LogicalBlock -EnumTrailingComma: Leave -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: true -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IfMacros: - - KJ_IF_MAYBE -IncludeBlocks: Preserve -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - SortPriority: 0 - CaseSensitive: false - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - SortPriority: 0 - CaseSensitive: false - - Regex: '.*' - Priority: 1 - SortPriority: 0 - CaseSensitive: false -IncludeIsMainRegex: '(Test)?$' -IncludeIsMainSourceRegex: '' -IndentAccessModifiers: false -IndentCaseBlocks: false -IndentCaseLabels: false -IndentExportBlock: true -IndentExternBlock: AfterExternBlock -IndentGotoLabels: true -IndentPPDirectives: None -IndentRequiresClause: true -IndentWidth: 2 -IndentWrappedFunctionNames: false -InsertBraces: false -InsertNewlineAtEOF: false -InsertTrailingCommas: None -IntegerLiteralSeparator: - Binary: 0 - BinaryMinDigitsInsert: 0 - BinaryMaxDigitsRemove: 0 - Decimal: 0 - DecimalMinDigitsInsert: 0 - DecimalMaxDigitsRemove: 0 - Hex: 0 - HexMinDigitsInsert: 0 - HexMaxDigitsRemove: 0 - BinaryMinDigits: 0 - DecimalMinDigits: 0 - HexMinDigits: 0 -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLines: - AtEndOfFile: false - AtStartOfBlock: true - AtStartOfFile: true -KeepFormFeed: false -LambdaBodyIndentation: Signature -LineEnding: DeriveLF -MacroBlockBegin: '' -MacroBlockEnd: '' -MainIncludeChar: Quote -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -NumericLiteralCase: - ExponentLetter: Leave - HexDigit: Leave - Prefix: Leave - Suffix: Leave -ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 2 -ObjCBreakBeforeNestedBlockParam: true -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -OneLineFormatOffRegex: '' -PackConstructorInitializers: BinPack -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakBeforeMemberAccess: 150 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakOpenParenthesis: 0 -PenaltyBreakScopeResolution: 500 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 0 -PenaltyIndentedWhitespace: 0 -PenaltyReturnTypeOnItsOwnLine: 60 -PointerAlignment: Right -PPIndentWidth: -1 -QualifierAlignment: Leave -ReferenceAlignment: Pointer -ReflowComments: Always -RemoveBracesLLVM: false -RemoveEmptyLinesInUnwrappedLines: false -RemoveParentheses: Leave -RemoveSemicolon: false -RequiresClausePosition: OwnLine -RequiresExpressionIndentation: OuterScope -SeparateDefinitionBlocks: Leave -ShortNamespaceLines: 1 -SkipMacroDefinitionBody: false -SortIncludes: - Enabled: true - IgnoreCase: false - IgnoreExtension: false -SortJavaStaticImport: Before -SortUsingDeclarations: LexicographicNumeric -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false -SpaceAfterOperatorKeyword: false -SpaceAfterTemplateKeyword: true -SpaceAroundPointerQualifiers: Default -SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeJsonColon: false -SpaceBeforeParens: ControlStatements -SpaceBeforeParensOptions: - AfterControlStatements: true - AfterForeachMacros: true - AfterFunctionDefinitionName: false - AfterFunctionDeclarationName: false - AfterIfMacros: true - AfterNot: false - AfterOverloadedOperator: false - AfterPlacementOperator: true - AfterRequiresInClause: false - AfterRequiresInExpression: false - BeforeNonEmptyParentheses: false -SpaceBeforeRangeBasedForLoopColon: true -SpaceBeforeSquareBrackets: false -SpaceInEmptyBraces: Never -SpacesBeforeTrailingComments: 1 -SpacesInAngles: Never -SpacesInContainerLiterals: true -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 -SpacesInParens: Never -SpacesInParensOptions: - ExceptDoubleParentheses: false - InCStyleCasts: false - InConditionalStatements: false - InEmptyParentheses: false - Other: false -SpacesInSquareBrackets: false -Standard: Latest -StatementAttributeLikeMacros: - - Q_EMIT -StatementMacros: - - Q_UNUSED - - QT_REQUIRE_VERSION -TableGenBreakInsideDAGArg: DontBreak -TabWidth: 8 -UseTab: Never -VerilogBreakBetweenInstancePorts: true -WhitespaceSensitiveMacros: - - BOOST_PP_STRINGIZE - - CF_SWIFT_NAME - - NS_SWIFT_NAME - - PP_STRINGIZE - - STRINGIZE -WrapNamespaceBodyWithEmptyLines: Leave -... - diff --git a/c/allocstrings.c b/c/allocstrings.c new file mode 100644 index 0000000..168135d --- /dev/null +++ b/c/allocstrings.c @@ -0,0 +1,44 @@ +/* + een programma dat newlines leest en ze dan weer print + + we gaan een scanf moeten maken die newlines leest en dan malloced voor elke +string + +scanf lijkt automatisch te stoppen op newlines, maar gaat wel onmiddelijk door totdat alle scanf's satisfied zijn + + */ + +#include +#include +#include + +#define WORDCOUNT 5 + +void storeinput(char input[], int index, char **strarr) { + char *myword = malloc(strlen(input) +1); + //*myword = *input; //blijkbaar hier strcpy voor nodig, want anders overwrite + //ik hier alleen maar de value van de pointer zelf + strcpy(myword, input); //myword is a pointer to allocated memory, but it's empty unless strcopy + printf("myword:%s\n", myword); + strarr[index] = myword; + printf("strarr:%s\n", strarr[index]); +} + +int main() { + // laten we eerst een array van pointers naar strings maken + char **strarr = malloc(sizeof(char *) * 10); + + // moeten nu een functie maken die individuele strings malloced? + + for (int i = 0; i < WORDCOUNT; i++) { + char temp[50]; + scanf("%s", temp); + storeinput(temp, i, strarr); + printf("wordin:%d %s\n", i, temp); + } + + for (int i = 0; i < WORDCOUNT; i++) { + printf("word:%d, %s\n", i, strarr[i]); + } + return 0; +} diff --git a/qscr/c/bits/converter/converter.c b/c/bits/converter/converter.c similarity index 98% rename from qscr/c/bits/converter/converter.c rename to c/bits/converter/converter.c index 73e7880..0ebdfd8 100644 --- a/qscr/c/bits/converter/converter.c +++ b/c/bits/converter/converter.c @@ -16,7 +16,7 @@ //might have to add some padding, but basic works void bintohex(char* string_in){ const char hexmap[] = "0123456789ABCDEF"; - char hexnum[4]; + char hexnum[4] = {}; int stringl = strnlen(string_in, 10)-1; //aantal nibbles int loopamount = stringl/4; diff --git a/c/files/parser/kvparser/cout b/c/files/parser/kvparser/cout new file mode 100755 index 0000000..866d869 Binary files /dev/null and b/c/files/parser/kvparser/cout differ diff --git a/c/files/parser/kvparser/couto b/c/files/parser/kvparser/couto new file mode 100755 index 0000000..4ce5675 Binary files /dev/null and b/c/files/parser/kvparser/couto differ diff --git a/c/files/parser/kvparser/hash_fnv.h b/c/files/parser/kvparser/hash_fnv.h new file mode 100644 index 0000000..6743fcb --- /dev/null +++ b/c/files/parser/kvparser/hash_fnv.h @@ -0,0 +1,7 @@ +#ifndef HASH_FNV_H +#define HASH_FNV_H + +#include +#include + +uint32_t hasher(void *data, size_t len); diff --git a/qscr/c/files/parser/kvparser/kvparser.c b/c/files/parser/kvparser/kvparser.c similarity index 100% rename from qscr/c/files/parser/kvparser/kvparser.c rename to c/files/parser/kvparser/kvparser.c diff --git a/qscr/c/files/parser/kvparser/kvtest.txt b/c/files/parser/kvparser/kvtest.txt similarity index 100% rename from qscr/c/files/parser/kvparser/kvtest.txt rename to c/files/parser/kvparser/kvtest.txt diff --git a/qscr/c/files/parser/kvparser/stringchicken.c b/c/files/parser/kvparser/stringchicken.c similarity index 95% rename from qscr/c/files/parser/kvparser/stringchicken.c rename to c/files/parser/kvparser/stringchicken.c index 133f1ac..506282d 100644 --- a/qscr/c/files/parser/kvparser/stringchicken.c +++ b/c/files/parser/kvparser/stringchicken.c @@ -36,7 +36,7 @@ void push_SC(char *string_input, struct stringchicken *struct_input){ struct_input->data = tempptr; } - char *newstring = malloc(strnlen(string_input+1, sizeof(char)*101)); + char *newstring = malloc(strnlen(string_input, 101)+1); strcpy(newstring,string_input); struct_input->data[struct_input->length] = newstring; diff --git a/qscr/c/files/parser/kvparser/stringchicken.h b/c/files/parser/kvparser/stringchicken.h similarity index 100% rename from qscr/c/files/parser/kvparser/stringchicken.h rename to c/files/parser/kvparser/stringchicken.h diff --git a/qscr/c/gai/fixedynarr.c b/c/gai/fixedynarr.c similarity index 100% rename from qscr/c/gai/fixedynarr.c rename to c/gai/fixedynarr.c diff --git a/qscr/c/gai/g4_l_ass.md b/c/gai/g4_l_ass.md similarity index 100% rename from qscr/c/gai/g4_l_ass.md rename to c/gai/g4_l_ass.md diff --git a/qscr/c/stringsort.c b/c/stringsort.c similarity index 100% rename from qscr/c/stringsort.c rename to c/stringsort.c diff --git a/c/ui/ncurses/cout b/c/ui/ncurses/cout new file mode 100755 index 0000000..88c8a73 Binary files /dev/null and b/c/ui/ncurses/cout differ diff --git a/c/ui/ncurses/hc.c b/c/ui/ncurses/hc.c new file mode 100644 index 0000000..c4e9413 --- /dev/null +++ b/c/ui/ncurses/hc.c @@ -0,0 +1,38 @@ +#include +#include + + + +int main(){ + initscr(); + noecho(); + cbreak(); + keypad(stdscr, TRUE); + curs_set(1); + + if(has_colors() == FALSE ) { + endwin(); + puts("no colors"); + return 1; + } + + start_color(); + init_pair(1, COLOR_WHITE, COLOR_BLUE); + attron(COLOR_PAIR(1)); + + int y,x; + getmaxyx(stdscr, y,x); + y=y*0.5; + x=(x*0.5) -6; + mvwprintw(stdscr, y, x, "Hello World"); + mvwprintw(stdscr, 2, 2, "Hellow World1"); + refresh(); + + attroff(COLOR_PAIR(1)); + + getch(); + + endwin(); + + return 0; +} diff --git a/cpp/functions/cmake/CMakeLists.txt b/cpp/functions/cmake/CMakeLists.txt new file mode 100644 index 0000000..b7ba785 --- /dev/null +++ b/cpp/functions/cmake/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.24) +project(cppout) + +file(GLOB SOURCE_FILES "*.cpp") + +add_executable(${PROJECT_NAME} ${SOURCE_FILES}) diff --git a/cpp/functions/cmake/hello.cpp b/cpp/functions/cmake/hello.cpp new file mode 100644 index 0000000..e9f8aba --- /dev/null +++ b/cpp/functions/cmake/hello.cpp @@ -0,0 +1,4 @@ +#include +void printhello(const char *name) { + printf("hello %s \n", name); + } diff --git a/cpp/functions/cmake/hello.h b/cpp/functions/cmake/hello.h new file mode 100644 index 0000000..ead8305 --- /dev/null +++ b/cpp/functions/cmake/hello.h @@ -0,0 +1 @@ +void printhello(const char *name); diff --git a/cpp/functions/cmake/main.cpp b/cpp/functions/cmake/main.cpp new file mode 100644 index 0000000..39372e8 --- /dev/null +++ b/cpp/functions/cmake/main.cpp @@ -0,0 +1,7 @@ +#include +#include "hello.h" +int main() { + printhello("test"); + + return EXIT_SUCCESS; +} diff --git a/cpp/functions/hw/cout b/cpp/functions/hw/cout new file mode 100755 index 0000000..3679064 Binary files /dev/null and b/cpp/functions/hw/cout differ diff --git a/cpp/functions/hw/main.cpp b/cpp/functions/hw/main.cpp new file mode 100644 index 0000000..a9f29b2 --- /dev/null +++ b/cpp/functions/hw/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + std::cout << "Hello, world"; + return 0; +} diff --git a/cpp/functions/sort/CMakeLists.txt b/cpp/functions/sort/CMakeLists.txt new file mode 100644 index 0000000..b7ba785 --- /dev/null +++ b/cpp/functions/sort/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.24) +project(cppout) + +file(GLOB SOURCE_FILES "*.cpp") + +add_executable(${PROJECT_NAME} ${SOURCE_FILES}) diff --git a/cpp/functions/sort/sort.cpp b/cpp/functions/sort/sort.cpp new file mode 100644 index 0000000..f7b7f22 --- /dev/null +++ b/cpp/functions/sort/sort.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +void bsort(std::vector &input_vec){ + /* + voor elk nummer i in k behalve de laatste + ga langs elk volgende nummer j behalve de laatste + en kijk of i+1 groter is dan i, als i groter is dan j, verplaats i naar +j + */ + + for (size_t i = 0; i < input_vec.size(); i++) { + printf("%zu\n", i); + for (size_t j = 0; j < input_vec.size()-1-i; j++) { + if (input_vec[j]>input_vec[j+1]) { + int temp = input_vec[j + 1]; + input_vec[j + 1] = input_vec[j]; + input_vec[j] = temp; + } + } + } +} + +// returns an array of length filled with random positive integers of up to max +std::vector createranarr(size_t input_length, size_t max){ + std::vector myv; + for (size_t i = 0; i < input_length; i++) { + myv.push_back(rand() % max); + } + return myv; +} + +void arrprinter(const std::vector &input_vec) { + for (size_t i = 0; i < input_vec.size(); i++) { + std::printf("number:%zu = %d\n",i, input_vec[i]); + } +} + +int main() { + std::vector myvector = createranarr(10, 100); + arrprinter(myvector); + bsort(myvector); + arrprinter(myvector); + return 0; +} diff --git a/cpp/ui/ncurses/hw/CMakeLists.txt b/cpp/ui/ncurses/hw/CMakeLists.txt new file mode 100644 index 0000000..b1a8ad7 --- /dev/null +++ b/cpp/ui/ncurses/hw/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.24) +project(cppout) + +file(GLOB SOURCE_FILES "*.cpp") + +find_package(Curses REQUIRED) +include_directories(${CURSES_INCLUDE_DIR}) + +add_executable(${PROJECT_NAME} ${SOURCE_FILES}) +target_link_libraries(${PROJECT_NAME} ${CURSES_LIBRARIES}) diff --git a/cpp/ui/ncurses/hw/hwcurses.cpp b/cpp/ui/ncurses/hw/hwcurses.cpp new file mode 100644 index 0000000..d5e94e5 --- /dev/null +++ b/cpp/ui/ncurses/hw/hwcurses.cpp @@ -0,0 +1,12 @@ +#include + +int main() { + initscr(); + move(11, 26); + printw("Hello curses"); + refresh(); + getch(); + endwin(); + + return 0; +} diff --git a/med/C-programming-a-modern-standard/5-2-4_number_comparison.c b/med/C-programming-a-modern-standard/5-2-4_number_comparison.c deleted file mode 100644 index 2861f52..0000000 --- a/med/C-programming-a-modern-standard/5-2-4_number_comparison.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "stdio.h" - -int main() -{ - int i = 5; - int j = 7; - int x; - - x = (i>j)-(j>i); - /* - * -1 if i less than j - * 0 if i equal to j - * +1 if i more than j - * */ - - printf("%d: ", x); - return 0; -} diff --git a/med/C-programming-a-modern-standard/digitseen.c b/med/C-programming-a-modern-standard/digitseen.c deleted file mode 100644 index 7518c6e..0000000 --- a/med/C-programming-a-modern-standard/digitseen.c +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include -#include -#include - -void numberprinter(int inarr[], int arrlength) { - for (int i = 0; i < arrlength; i++) { - printf("number%d: %d\n", i, inarr[i]); - } -} - -struct Darray { - int *digits; - size_t length; // blijkbaar correcte eenheid voor length, malloc stuff ofzo (instead of hardcoding it) -}; - -struct Darray *numbertodigitDarr(int input) { - - // same calculation for arrsize - int op = 0; - int tempinput = input; - while (tempinput) { - tempinput /= 10; - op++; - } - - // allocate memory for struct and array, apparently more ideomatic to have a single malloc - struct Darray *DigDarr = - malloc(op * sizeof(int) + sizeof(*DigDarr) + sizeof(int)); - if (DigDarr == NULL) { - printf("allocation failed"); - exit(0); - } - // forgot to assign a value to the pointer variable in the struct. - DigDarr->digits = (int *)(DigDarr + 1); - DigDarr->length = op; - - // insert numbers into array in reverse order - for (int i = op - 1; i >= 0; i--) { - int last_digit = input % 10; - printf("last digit: %d\n", last_digit); - DigDarr->digits[i] = last_digit; - input /= 10; - } - - return DigDarr; -} - -// -void checkarrdupes(struct Darray input) { - for (int i = 0; i < input.length; i++) { - printf("digitstr: %d\n", input.digits[i]); - } - - int digit_seen[10] = {}; - - // kijk door elke arr element - for (int i = 0; i < input.length; i++) { - // kijk of input[i] al in digit_seen zit - if (digit_seen[input.digits[i]]) { - printf("duplicate number: %d\n", input.digits[i]); - } else { - digit_seen[input.digits[i]] = 1; - } - } -} - -int main(void) { - - int n; - - printf("enter a number: "); - // TODO: scanf is fragile. Try using fgets() and strtol() for robust input - // sanitization. - scanf("%d", &n); - int digitslength = 0; - struct Darray *mydigitsDarr = numbertodigitDarr(n); - - checkarrdupes(*mydigitsDarr); - - free(mydigitsDarr); - return 0; -} -/* - somehow I have to find a way to get the number of digits in my number - for now, we use modulo. whatever remains is the last digit of the number - we then divide by 10 to remove the last number - -we can keep a counter, and we can put it into an array. however, if we use the -iterator (which has to start from 0, because we don't know the size of the -number?) then our number will be the wrong way around. - -malloc, blijkbaar very different - */ diff --git a/med/C-programming-a-modern-standard/dweight.c b/med/C-programming-a-modern-standard/dweight.c deleted file mode 100644 index aa30f6b..0000000 --- a/med/C-programming-a-modern-standard/dweight.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "stdlib.h" -#include "stdio.h" - -int main(void) -{ - float height, length, width, volume, weight; - printf("Enter height of box: "); - scanf("%f", &height); - printf("Enter length of box: "); - scanf("%f", &length); - printf("Enter width of box: "); - scanf("%f", &width); - - volume = height * length * width; - weight = (volume + 165) / 166; - - printf("Dimensions: %fx%fx%f\n", length, width, height); - printf("Volume: %f\n", volume); - printf("Weight: %f\n", weight); -} diff --git a/med/C-programming-a-modern-standard/numberreversal.c b/med/C-programming-a-modern-standard/numberreversal.c deleted file mode 100644 index b451b22..0000000 --- a/med/C-programming-a-modern-standard/numberreversal.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "stdio.h" -#include "stdlib.h" - -int main(){ - - int input; - printf("input:"); - scanf("%d", &input); - - // assume 3 digits, - - int d1, d2, d3; - d1 = input / 100; //uitgaande van flooring - d2 = input % 100 / 10; - d3 = input % 10; - - printf("%d%d%d",d3, d2,d1); - - printf("next: "); - scanf("%1d%1d%1d", &d1,&d2,&d3); - printf("%d%d%d",d3,d2,d1); - - return 0; -} diff --git a/med/C-programming-a-modern-standard/pun.c b/med/C-programming-a-modern-standard/pun.c deleted file mode 100644 index 0aa031c..0000000 --- a/med/C-programming-a-modern-standard/pun.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "stdio.h" - -int main(void) -{ - printf("To C, or not to C: that is the question.\n"); - return 0; -} diff --git a/med/C-programming-a-modern-standard/timeconverter.c b/med/C-programming-a-modern-standard/timeconverter.c deleted file mode 100644 index e4549b5..0000000 --- a/med/C-programming-a-modern-standard/timeconverter.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "stdio.h" - -int main() -{ - - /* - * modify 24 hour time to 12 hour - * take first 2 numbers, - * if numbers <=12, AM - * else PM - * */ - - int i ; int j; char c; - printf("input time: "); - scanf("%2d%1c%2d", &i,&c, &j); - printf("int i: %d int j: %d\n", i, j); - - if(i!=12&&j==00){ - i%=12; - } - - - if(i <=12){ - printf("%d:%.2d AM",i,j); - } else { - printf("%d:%.2d PM",i,j); - } - - return 0; -} diff --git a/qscr/c/a.out b/qscr/c/a.out deleted file mode 100755 index ef19770..0000000 Binary files a/qscr/c/a.out and /dev/null differ diff --git a/qscr/c/files/parser/kvparser/Makefile b/qscr/c/files/parser/kvparser/Makefile deleted file mode 100644 index 57e2ddf..0000000 --- a/qscr/c/files/parser/kvparser/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -CC = gcc -CFLAGS = -Wall -Wextra -g -TARGET = cout - -# Directories -BUILD_DIR = build - -# Source files -SRCS = $(wildcard *.c) -# This transforms "main.c" into "build/main.o" -OBJS = $(patsubst %.c, $(BUILD_DIR)/%.o, $(SRCS)) - -# Default target -all: $(TARGET) - -# Link the object files in the build directory into the final executable -$(TARGET): $(OBJS) - $(CC) $(OBJS) -o $(TARGET) - -# Compile .c files into .o files inside the build directory -$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR) - $(CC) $(CFLAGS) -c $< -o $@ - -# Create the build directory if it doesn't exist -$(BUILD_DIR): - mkdir -p $(BUILD_DIR) - -# Clean up the build directory and the executable -clean: - rm -rf $(BUILD_DIR) $(TARGET) - -.PHONY: all clean diff --git a/qscr/c/files/parser/kvparser/compile_commands.json b/qscr/c/files/parser/kvparser/compile_commands.json deleted file mode 100644 index 6d90a55..0000000 --- a/qscr/c/files/parser/kvparser/compile_commands.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "file": "kvparser.c", - "arguments": [ - "/usr/bin/gcc", - "-Wall", - "-Wextra", - "-g", - "-c", - "kvparser.c", - "-o", - "build/kvparser.o" - ], - "directory": "/home/lyr41n/mycode/ler/exc/qscr/c/files/parser/kvparser", - "output": "build/kvparser.o" - } -] \ No newline at end of file diff --git a/qscr/c/learnc/aptr.c b/qscr/c/learnc/aptr.c deleted file mode 100644 index 8ca0711..0000000 --- a/qscr/c/learnc/aptr.c +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include - -int main() { - int i, j; - /* TODO: define the 2D pointer variable here */ - int ** pnumbers; - - /* TODO: complete the following line to allocate memory for holding three rows */ - pnumbers = (int **) malloc(sizeof(int)*6); - - /* TODO: allocate memory for storing the individual elements in a row */ - pnumbers[0] = (int *) malloc(1 * sizeof(int)); - pnumbers[1] = (int *) malloc(2 * sizeof(int)); - pnumbers[2] = (int *) malloc(3 * sizeof(int)); - - pnumbers[0][0] = 1; - pnumbers[1][0] = 1; - pnumbers[1][1] = 1; - pnumbers[2][0] = 1; - pnumbers[2][1] = 2; - pnumbers[2][2] = 1; - - for (i = 0; i < 3; i++) { - for (j = 0; j <= i; j++) { - printf("%d", pnumbers[i][j]); - } - printf("\n"); - } - - for (i = 0; i < 3; i++) { - /* TODO: free memory allocated for each row */ - free(pnumbers[i]); - } - - /* TODO: free the top-level pointer */ - free(pnumbers); - return 0; -} diff --git a/qscr/c/learnc/bsort.c b/qscr/c/learnc/bsort.c deleted file mode 100644 index 01cc282..0000000 --- a/qscr/c/learnc/bsort.c +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -#include - -struct Darray { - int size; - int data[]; //flexible array member -}; - -//randomized array -void rarr(struct Darray *darr) { - for (int i=0; isize; ++i) { - darr->data[i] = rand() % 32; - } - if (darr == NULL) { - printf("failed"); - exit(1); - } -} - -struct Darray *createdarray(int mysize){ - struct Darray *darrstruct = malloc(mysize * sizeof(int) + sizeof(*darrstruct)); - - if (darrstruct == NULL) { - printf("failed"); - exit(1); - } - - darrstruct->size = mysize; - rarr(darrstruct); - - return darrstruct; -} - -void msort(int *myarr, int mysize) { - for (int i = 0 ; i < mysize; i++) { - for (int j = 0 ; j < mysize ; j ++) - if (myarr[i] > myarr[j]) { - int k = myarr[i]; - myarr[i] = myarr[j]; - myarr[j] = k; - } - } -} - -void bsort(struct Darray *myarr) { - for (int i = 0; i < myarr->size; i++) { - for (int j = 0; j < myarr->size -1 ; j++ ) { - if (myarr->data[j] < myarr->data[j+1]) { - int k = myarr->data[j]; - myarr->data[j] = myarr->data[j+1]; - myarr->data[j+1] = k; - } - } - } - } - -int main() { - srand(time(NULL)); - int mysize = 7; - struct Darray *myarray; - myarray = createdarray(mysize); - - printf("myarr:\n"); - for (int i = 0 ; i < myarray->size; i++) { - printf("%d\n", myarray->data[i]); - } - - bsort(myarray); - - printf("sorted myarr:\n"); - for (int i = 0 ; i < myarray->size; i++) { - printf("%d\n", myarray->data[i]); - } - - free(myarray); - - return 0; - -} diff --git a/qscr/c/learnc/linkedlist.c b/qscr/c/learnc/linkedlist.c deleted file mode 100644 index d8fa639..0000000 --- a/qscr/c/learnc/linkedlist.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -struct node { - int val; - struct node * next; -}; - -struct node_t * head = NULL; -head = (struct node_T*)malloc(sizeof(struct node_t)); - -int main(){ - - return 0; -} diff --git a/qscr/c/learnc/pascaltriangle.c b/qscr/c/learnc/pascaltriangle.c deleted file mode 100644 index e8213bc..0000000 --- a/qscr/c/learnc/pascaltriangle.c +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -int *pascallarr(int iarrsize, int *ptr){ - int *mypascallar = malloc(sizeof(int) * iarrsize + 1); - /* declare edges, as they're always 1 anyways so we can start the loop at 1 (so i-1 = 0) */ - mypascallar[0] = 1; - mypascallar[iarrsize] = 1; - for (int i = 1; i <= iarrsize; i++) { - if (i < iarrsize) { - mypascallar[i] = ptr[i-1] + ptr[i]; - } - } - return mypascallar; -} - -int main() { - int trianglesize = 18; - int ** pnumbers; - - /* create pascals triangle, on row i, we have i numbers */ - - /* should create 2d array of ints, with an array of pointers to arrays*/ - - int **ptrtriangle = malloc(sizeof(int *)*trianglesize); - - /* need to create a function that returns the pointer to an array of i numbers filled with numbers */ - for (int i = 0; i < trianglesize; i++) { - ptrtriangle[i] = pascallarr(i,ptrtriangle[i-1]); - for (int j = 0; j <= i; j++) { - printf("%d|",ptrtriangle[i][j]); - } - printf("\n"); - } - return 0; -} diff --git a/qscr/c/learnc/rec.c b/qscr/c/learnc/rec.c deleted file mode 100644 index 5e74649..0000000 --- a/qscr/c/learnc/rec.c +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include - -int recfact(int x){ - int y = 1; - if (x==1){ - return y; - } else { - return y *= x *recfact(x-1); - } -} - -int recfor(int x){ - int gaga = 1; - for (int i = 1; i < x;) { - gaga *= i++; - } - return gaga; -} - -/* - * i = 1, gaga = 1*2 - * i = 2, gaga = 1*2*3 = 6 - * i = 3, 1*2*3*4 = 24 - * - * wrong loop time condition - * wrong calculation - * - * --- - * - * recursion - * - * forgot to assign, forgot a number (multiplied by 0) - * misunderstood calculation - - wel exploren, maar wel naar een doel. - kijken naar auxililiaries. - curiosity wss, leren vragen. leren wat ik niet heb, weten wat ik niet weet. - - zoektocht heeft wat sturing nodig. - - hoe ik mijn probeer stel/vind - het probleem onderzoeken - - limiteer de pogingen - - - hardware / networking - * * */ - -int main () { - int i = 6; // we can not handle negative numbers - - printf("%d\n", recfor(i)); - printf("%d\n", recfact(i)); - - return 0; -} diff --git a/qscr/c/learnc/rec2.c b/qscr/c/learnc/rec2.c deleted file mode 100644 index 3ffdcfc..0000000 --- a/qscr/c/learnc/rec2.c +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include - -/* - * factorials - * - * in both for loop, as well as recursive - * factorial: voor int i, vermenigvuldig dan elke i to je bij 1 komt (uit gaande van positive ints) - * - * dus, f(3)=3*2*1 = 6 ; f(4)=4*3*2*1=24 ; f(a)=no ; f(-2)= no ; f(2.1) = no - * - * will use 2 functions: - * recfac using recursion - * itfac using iteration - * - * should probably figure out how to test this? maybe a dumb K:V? - * * */ - -int recfact(int input){ - int fac = 1; - if (input==1) { - return fac; - } - else { - fac *= input * recfact(input-1); - } -} - -int itfact(int input){ - int sum = 1; - for (int i = 1; i <= input; i++) { - sum *= i; - } - return sum; -} - -int main(){ - - int input = 5; - - //recfact(input); - //itfact(input); - printf("%d\n", recfact(input)); - printf("%d\n", itfact(input)); - return 0; -}