changed structure
This commit is contained in:
-322
@@ -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
|
||||
...
|
||||
|
||||
@@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
@@ -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;
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
#ifndef HASH_FNV_H
|
||||
#define HASH_FNV_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t hasher(void *data, size_t len);
|
||||
+1
-1
@@ -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;
|
||||
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,38 @@
|
||||
#include <ncurses.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(cppout)
|
||||
|
||||
file(GLOB SOURCE_FILES "*.cpp")
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
|
||||
@@ -0,0 +1,4 @@
|
||||
#include <cstdio>
|
||||
void printhello(const char *name) {
|
||||
printf("hello %s \n", name);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
void printhello(const char *name);
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <cstdlib>
|
||||
#include "hello.h"
|
||||
int main() {
|
||||
printhello("test");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello, world";
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(cppout)
|
||||
|
||||
file(GLOB SOURCE_FILES "*.cpp")
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
|
||||
@@ -0,0 +1,47 @@
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
void bsort(std::vector<int> &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<int> createranarr(size_t input_length, size_t max){
|
||||
std::vector<int> myv;
|
||||
for (size_t i = 0; i < input_length; i++) {
|
||||
myv.push_back(rand() % max);
|
||||
}
|
||||
return myv;
|
||||
}
|
||||
|
||||
void arrprinter(const std::vector<int> &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<int> myvector = createranarr(10, 100);
|
||||
arrprinter(myvector);
|
||||
bsort(myvector);
|
||||
arrprinter(myvector);
|
||||
return 0;
|
||||
}
|
||||
@@ -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})
|
||||
@@ -0,0 +1,12 @@
|
||||
#include <ncurses.h>
|
||||
|
||||
int main() {
|
||||
initscr();
|
||||
move(11, 26);
|
||||
printw("Hello curses");
|
||||
refresh();
|
||||
getch();
|
||||
endwin();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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
|
||||
*/
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "stdio.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("To C, or not to C: that is the question.\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Binary file not shown.
@@ -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
|
||||
@@ -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"
|
||||
}
|
||||
]
|
||||
@@ -1,39 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
struct Darray {
|
||||
int size;
|
||||
int data[]; //flexible array member
|
||||
};
|
||||
|
||||
//randomized array
|
||||
void rarr(struct Darray *darr) {
|
||||
for (int i=0; i<darr->size; ++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;
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
Reference in New Issue
Block a user