Please upvote if you like the post, so that it can reach broader Audience, who are looking for Omicron Experience.
$ cat test.c
int main() {
int a = 42;
printf("%d\n",a);
}
//In C it compiles with warning. Because libc(C Standard library) has defined it already.
$ gcc test.c
test.c:3:5: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
printf("%d\n",a);
^~~~~~
test.c:3:5: warning: incompatible implicit declaration of built-in function ‘printf’
test.c:3:5: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
//In C++ did not compile. C++ always need header include
$ g++ test.c
test.c: In function ‘int main()’:
test.c:3:5: error: ‘printf’ was not declared in this scope
printf("%d\n",a);
3 Mistakes in question:
a. return statement missing from main. Return value is stored in rax which presently stores 3 (return value from printf) which is wrong.
b. Header file include is missing
c. main() should be main(int argc, char** argv) typedef struct node {
int val;
node* next;
node* prev;
}Node;
Implement 3 functions:
1. void InitializeToNull(Node** ptr); //Initialize a head pointing to null
2. void AddAfter (Node** head, int position, Node node); //Add a node inside DLL after position p.
3. void RemoveNode (Node** head, int val) //Remove element from Doubly Linked Liststring strInput = "abcd";
void gen_combinations(vector<string>& vecOut, string& outstr, int index) {
for (int i = index; i < strInput.length(); i++) {
outstr += strInput[i];
//cout << outstr<<"\n";
vecOut.push_back(outstr);
gen_combinations(vecOut, outstr, i + 1);
outstr.erase(outstr.length() - 1,1); //erase(length, position)
}
}
void print_groupings(vector<string>& vecInput) {
bool af, bf, cf, df;
for (auto i : vecInput) {
i.find("a") != string::npos ? af = true : af = false;
i.find("b") != string::npos ? bf = true : bf = false;
i.find("c") != string::npos ? cf = true : cf = false;
i.find("d") != string::npos ? df = true : df = false;
if (af && df) {
//A does not go with D
}
else if (af && cf && bf) {
//if A & C goes, B will not go
}
else if (af && cf) {
//if A does not go, D or C goes.
}
else if (bf && !cf) {
//B will always go with C. If B present & C not skip
}
else
cout << i << "\n";
}
}
int main() {
vector<string> vecOut;
string out;
gen_combinations(vecOut, out, 0);
print_groupings(vecOut);
return 0;
}
$ ./a.out
a
bc
bcd
c
cd
dvoid log (const std::string& message);log() method should queue the messages and process asynchronously in another thread.