Search:

Type: Posts; User: christop

Page 1 of 20 1 2 3 4

Search: Search took 0.01 seconds.

  1. Before you write code, write down detailed...

    Before you write code, write down detailed step-by-step instructions in English (or whatever language you're most comfortable with) on how you would accomplish the task. Think of it like a recipe: 1....
  2. Replies
    10
    Views
    228

    Replace "CPU" with "compiler" and you'd be...

    Replace "CPU" with "compiler" and you'd be correct. The "register" keyword is still recognized but doesn't have much (if any) effect anymore with modern optimizing compilers (they know which...
  3. Replies
    49
    Views
    913

    Incidentally, I mentioned using the Fisher-Yates...

    Incidentally, I mentioned using the Fisher-Yates algorithm in #4 and gave some code in #10 that does basically what you suggested. It seems like wolly either isn't reading or isn't understanding our...
  4. Replies
    4
    Views
    139

    Each node is linked to the previously-allocated...

    Each node is linked to the previously-allocated node, making all nodes accessible, so there's no memory leak (except at the very end of the program because the nodes in the linked list are not freed).
  5. Replies
    8
    Views
    419

    Also here: program for a tough problem....

    Also here: program for a tough problem.
  6. Replies
    4
    Views
    172

    By the way, this line: structure_variable =...

    By the way, this line:


    structure_variable = malloc (sizeof(structure_variable));

    should be:


    structure_variable = malloc (sizeof(*structure_variable));
  7. Replies
    6
    Views
    131

    C'mon, are you just trolling us now? I numbered...

    C'mon, are you just trolling us now? I numbered the rows for you.

    Your new code is correct, by the way.
  8. Replies
    6
    Views
    131

    The array has only 2 rows. How many rows are you...

    The array has only 2 rows. How many rows are you trying to fit in it? I counted 3:


    int array [2][3][4] =



    {
    { {1, 2, 3}, { 4, 5, 6} }, //...
  9. Replies
    49
    Views
    913

    You need to put something between the numbers if...

    You need to put something between the numbers if you want something between the numbers. It's up to you whether that's a space, newline, comma, or something else. Just add the number separator to the...
  10. Unlike Python, indentation means nothing to C....

    Unlike Python, indentation means nothing to C. Statements are grouped together (a "compound statement") with braces.
  11. Replies
    5
    Views
    227

    First things first: don't call main(). It's not...

    First things first: don't call main(). It's not necessary. If you want to return to the function that called your function, use a return statement.

    Second, what do you see if you print out the...
  12. Replies
    49
    Views
    913

    My take at it: void pick_n(int n, int out[])...

    My take at it:


    void pick_n(int n, int out[])
    {
    int pool[POOL_SIZE];
    for (int i = 0; i < POOL_SIZE; ++i) {
    pool[i] = i + 1;
    }
    int top = POOL_SIZE;
  13. Replies
    49
    Views
    913

    That description sounds like the Fisher-Yates...

    That description sounds like the Fisher-Yates shuffling algorithm, except it "shuffles" only 6 numbers and leaves the rest in place.

    So yes, it's a good start.
  14. Replies
    10
    Views
    308

    A compiler that doesn't initialize global...

    A compiler that doesn't initialize global variables is non-standard and should be used with care (or, if possible, discarded in favor of one that does follow the relevant standard(s)).
  15. Post your latest code and we can help.

    Post your latest code and we can help.
  16. Why would the texts not be synchronized? If you...

    Why would the texts not be synchronized? If you properly use a mutex in the threads to read lines from the stream, the threads will be synchronized.

    This is roughly how I'd do it:


    In the...
  17. One issue I see is that you're opening the file...

    One issue I see is that you're opening the file in each thread (and then saving the file handle in a shared variable, fp). It should be opened only once, before the first thread starts.

    Another...
  18. Replies
    5
    Views
    210

    Also be careful not to use recursion where it's...

    Also be careful not to use recursion where it's not warranted. menu() calls write_func(), which calls add_entry() or remove_entry(), which then calls menu(). Instead of calling menu(), just use a...
  19. Thread: Help Required

    by christop
    Replies
    3
    Views
    182

    It's not an empty line at the end of the file, as...

    It's not an empty line at the end of the file, as a lot of people seem to believe. It's a newline character at the end of each line. A text file with n lines has exactly n newline characters, so a...
  20. Which line gets a value for v? Look closely.

    Which line gets a value for v? Look closely.
  21. What is the value of "v" at this line?

    What is the value of "v" at this line?
  22. Replies
    15
    Views
    386

    Returning a value from a function in all cases...

    Returning a value from a function in all cases isn't really adding an error check. The compiler makes it pretty easy to catch where a function fails to return a value too. You don't even need the...
  23. Replies
    33
    Views
    736

    I'm fairly certain that Hodor knows exactly what...

    I'm fairly certain that Hodor knows exactly what conio.h is and what ch == 93 is supposed to mean. I took their questions to be rhetorical to help the OP think about them to help them improve their...
  24. Replies
    33
    Views
    736

    Haha, good point. In that case my code will print...

    Haha, good point. In that case my code will print "hello". (It's not that clear how to "properly" handle cases like this, as the specifications I've seen in this thread are fairly loose.)
  25. Replies
    33
    Views
    736

    Why not skip the buffer completely? It's not...

    Why not skip the buffer completely? It's not necessary:


    #include <stdio.h>#include <stdbool.h>


    int main(int args, char *argv[]) {


    FILE *fp = fopen("text.txt", "r");
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4