- Strength to Increase Rep
- +6
- Strength to Decrease Rep
- -1
- Upvotes Received
- 81
- Posts with Upvotes
- 74
- Upvoting Members
- 57
- Downvotes Received
- 29
- Posts with Downvotes
- 17
- Downvoting Members
- 14
Re: Attempted the things others attempted.. #include <stdio.h> #include <stdbool.h> #include <string.h> void remove_even (int data[], const unsigned int size); void print_spiral (const unsigned int size); static void print_spiral_line (const unsigned int n, const unsigned int line); bool can_be_palindrome (char text[], const unsigned int size, const bool middle_found); /** * Write … | |
| |
Re: You can construct the value of any coin, using coins of lower value (if there are any); this makes the problem easier because the smallest amount of coins required is then obtained by repeatedly paying with the highest value coin, until the remaining cost is 0 (it would be diffent … | |
Re: ![9f16e3f185e5249f5fccda750957f0ce](/attachments/large/2/9f16e3f185e5249f5fccda750957f0ce.jpg "9f16e3f185e5249f5fccda750957f0ce") | |
Re: #include <iostream> #include <string> #include <algorithm> #include <functional> #include <cctype> using namespace std; int main() { /* Assumption: substring may overlap. E.g: "aaa" contains "aa" two times. */ const string HAYSTACK = "abbaabbaabb"; const string NEEDLE = "abba"; int counter = 0; /* A custom compare function for case-insensitive comparing … | |
Re: #include <iostream> #include <algorithm> #include <vector> #include <functional> using namespace std; /* Just a helper function that prints the contents of the vector, separated by a space */ void print_vector(vector<int> data) { for (auto elem : data) cout << elem << ' '; } /* Uses the <algorithm> function to … | |
Re: #include <iostream> #include <string> #include <map> #include <algorithm> using namespace std; int main() { /* Looks like you want something like a bimap, which isn't in the STL */ /* so using a single map here, and swapping the key / value pairs */ /* later to avoid redundancyto some … | |
Re: #include <assert.h> #include <stdbool.h> #include <stdlib.h> #include <string.h> #include <stdio.h> /******** Stack *********/ const unsigned STACK_INTIAL_ALLOC_SZ = 8; typedef struct { void* elems; /* The elements that are stored in the stack. */ unsigned elem_sz; /* The size in bytes of the elements stored in the stack. */ unsigned size; … | |
Re: For C-Strings you could take a look at the [cstring library](http://www.cplusplus.com/reference/cstring/), which contains a function named *strlen*. While you're not looking for a user-defined function, you could also define it yourself as it's quite straight forward. It'd look similar to this: constexpr size_t strlen (const char text[]) { // Note: … | |
Re: > After its standardization , array size can be specified with a variable. While C supports [VLAs](http://en.wikipedia.org/wiki/Variable-length_array) since the C99 standard, C++ does not support them as can be read in the [standard (8.3.4.1)](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf). | |
Re: > what could we do if theirare more than 10000000000 words? We could then ask this on Daniweb by bumping a 6 year old thread after which we could demolish our computer never to touch one ever again. | |
Re: Do you mean to do something like this? #include <stdio.h> #include <windows.h> static HHOOK _hook; static BOOL _control_pressed = FALSE; static const char _clipboard_text[] = "Hello world!"; static unsigned _clipboard_text_sz = sizeof(_clipboard_text); LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { PKBDLLHOOKSTRUCT kb = (PKBDLLHOOKSTRUCT) lParam; HGLOBAL hGlobal; char* pGlobal; … | |
Re: Right, so you have this figure of a certain height. When looking at the provided example you can clearly see there's some logic behind it; when asked to draw this figure of height 5 you'd be able to do it. So let's start with gathering information. We know how the … | |
Re: > for loop. Is this loop supposed to have a body? Effectively, all it does is set x to 0. But since x = 0, when the program reaches the switch blocks nothing happens. The next for loop forms the body of this loop. > 1) Line 15 is a … | |
Re: #include <stdio.h> #include <ctype.h> #include <string.h> #include <assert.h> #define LINE_WIDTH (15) #define BUFFER_SIZE (1024) char* word_wrap ( char* buffer, const unsigned int buffer_sz, const char* string, const unsigned int string_len, const unsigned int max_line_width) { assert(buffer != NULL && buffer_sz > 0 && string != NULL && string_len > 0 … | |
Re: If `a` is an integer it doesn't (really) make much sense to do it. | |
Re: Something like this? #include <stdio.h> #include <math.h> #include <stdbool.h> #define LOWER_BOUND (0) #define UPPER_BOUND (1000000) // Not inclusive. typedef void (*prime_callback)(unsigned int); static unsigned int digit_prime_count = 0; static const unsigned int M = 10; // Starting from 1. bool is_prime(const unsigned int n) { int i; if (n >= … | |
Re: > what is the code to display "*" as pyramid? #include <stdio.h> static void print_n(const char symbol, unsigned int n) { while (n --> 0) printf("%c", symbol); } void print_pyramid(const unsigned int height) { int i = 0, width = 0; const int WIDTH_TOTAL = (2 * height) - 1; … | |
Re: What is there to explain? `malloc` (attempts to) allocate a given amount of memory on the heap. It doesn't really know (or cares) what you're going to put there so it returns a void pointer so you'll have to cast it to a pointer matching the data you're putting in … | |
Re: normally an integer datatype hold 2 byes of memory.If Int is declared it holds 2 bytes by default. This is not true. The amount of bytes an integer takes up depends on the supported word size of the used CPU and there is no "default" specified in the specification. 32-bit … | |
Re: Not having a compiler handy, so treat the following as kind-of pseudo code, but if performance is no requirement you could define it as bool isMono(const tNode* t) { if (t == NULL) return true; else return tsearch(t->info, t->left) == NULL && tsearch(t->info, r->right) == NULL && isMono(t->left) && isMono(r->right); … | |
Re: That's some shady company asking their candidates questions like that.. | |
Re: `p` is an array of pointers. `*(p+i)` could be written as `p[i]` and `*(p[i] + j)` could likewise be written as `p[i][j]`. (So `*(*(p+i)+j)` could be written as `p[i][j]`) (and the contents of `p` are offsets off `a` which is 2-dimensional) So you could write that `printf` as: `printf("%d %d … | |
| |
Re: Your code is a mixture of C and C++ conventions, you should choose one or the other. As you posted this in the C section I assume you want C code. What do you want to do with newlines? Do you want to skip them entirely? You also don't have … | |
Re: #include <stdio.h> int main(void) { const char* string_before = "f a1 2 5 ffffffde 23 fffffff1 4 b0"; const char* string_after = "f a1 2 5 de 23 f1 4 b0"; printf("The C-code resulted in: \"%s\".\n", string_after); return 0; } | |
Re: I'm not fully sure if I get what you mean with your example, but I think you might be looking for a [map](http://www.cplusplus.com/reference/map/map/)? If not, please be more clear about what you mean with `list[i]` and `list[i_the_second]`. | |
Re: Relevant fragements from the C(99) specification (http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf): 6.2.4 Storage durations of objects ----------------------------------- The lifetime of an object is the portion of program execution during which storage is guaranteed to be reserved for it. An object exists, has a constant address,25) and retains its last-stored value throughout its lifetime.26) If … | |
Re: You are comparing indexes to string values. In addition there seemed to be some logic mistakes. Here's an attempt to fix them for you: void fold(char s[], int l) { int i, j, foldHere; i = j = 0; foldHere = FOLDLENGTH; while (i < l) { // We are … |