[Solved] Simple Code Optimisation

[ad_1] If you need to be able to reference lil_patate elsewhere in your code then you can’t make this factorisation at all. If you don’t need to refer to lil_patate elsewhere then get rid of it and initialise patate directly from q_nutrients: string patate(to_string(q_nutriments)); However, while this may improve the readability of the code, it … Read more

[Solved] Printing 2d array box

[ad_1] Something like this could work. You need basic understanding of nested loops to be able to do this question. #include <stdio.h> #include <stdlib.h> int main(int argc, char const *argv[]) { int rows, cols, i, j; printf(“Enter rows for box: “); if (scanf(“%d”, &rows) != 1) { printf(“Invalid rows\n”); exit(EXIT_FAILURE); } printf(“Enter columns for box: … Read more

[Solved] How to create a server which creates a new thread for each client? [closed]

[ad_1] Basically, what you’re looking for is something like this : #include <sys/types.h> #include <sys/socket.h> #include <pthread.h> void* handle_connection(void *arg) { int client_sock = *(int*)arg; /* handle the connection using the socket… */ } int main(void) { /* do the necessary setup, i.e. bind() and listen()… */ int client_sock; pthread_t client_threadid; while((client_sock = accept(server_sock, addr, … Read more

[Solved] SPOJ – Life, the Universe, and Everything

[ad_1] Two mistakes: Remove this line- printf(“Input:- \n”); In question you have to print before coming 42. If 42 has come you have to break. Like this: if(n!=42) printf(“%d\n”,n); else break; [ad_2] solved SPOJ – Life, the Universe, and Everything

[Solved] C++ Threading Error

[ad_1] The issue: you are calling join method for empty thread – you cannot do this, when you call join on non-joinable thread you will get exception. In this line thread threads[MAX_THREADS]; you created MAX_THREADS threads using its default constructor. Each thread object after calling default ctor is in non-joinable state. Before calling join you … Read more

[Solved] C++ Using Object with pass function [closed]

[ad_1] GradeBook::Grade is a non-static member function, it needs to operate on an instance of GradeBook. You can’t pass it in to a function expecting a plain function pointer. You could change TESTobj::SET to accept std::function objects, then wrap your member function in a lambda: void TESTobj::SET(std::function<void()> nu) void GradeBook::Set() { OBJ.SET([this](){Grade();}); OBJ.Test(); } [ad_2] … Read more

[Solved] array function C++

[ad_1] bool equivalent(int a[], int b[], int n) { int i=0, j=0, count=0; // This condition fails immediately because the values are equal while (a[i] != b[j]) { // For this reason neither count nor j are incremented count++; j++; } for (int i=0; i<=n; i++) // This condition succeeds immediately because these values are … Read more

[Solved] print empty asterisk triangle c

[ad_1] you just need to think that first line should be filled with *. Second thing is first character of every line should be *. and last character should also be *. and in between you need to fill spaces. int main() { int n=6; for(int i=n-1;i>=0;i–) // using n-1, bcz loop is running upto … Read more

[Solved] C# – No overload for method “getal” takes 1 argument

[ad_1] The error is saying there’s not method getal that has a string parameter. You’re invoking getal with txtNumber.text (string) as argument and the compiler is looking for a getal method with a string parameter and can’t find it. The existing getal method doesn’t take any parameters. public int getal(string x) { _a += _a; … Read more

[Solved] using reference in iteration of array

[ad_1] It certainly depends on what the body of the loop does. With no body to the loop, both will just completely discard the entire loop. There’s nothing different about the code that can be generated in either case. The & case-A has the most likelihood of being able to discard needless operations (like copying … Read more

[Solved] How to write async linq

[ad_1] Poor man’s async/await await Task.Factory.StartNew(() => PopulateList()); EDIT For those who want to see the usage of it How can i send email one after one in a row? and its follow-up question How do i make that it will send the email only once? 3 [ad_2] solved How to write async linq

[Solved] Inheritance of a template class [closed]

[ad_1] You can maybe do something like this: template <typename T> class store_impl { public: store_impl(T value) : value(value) {} private: T value; } // default class accepting any type // provides the default methods template <typename T> class store: public store_impl<T> { public: store(T value) : store_impl(value) {} } // specialization for int with … Read more