Search:

Type: Posts; User: john.c

Page 1 of 20 1 2 3 4

Search: Search took 0.01 seconds.

  1. Here is a clean-up of your code. 'fin' only...

    Here is a clean-up of your code.

    'fin' only has space for one address (and it has a global doppleganger for some reason). So once count is incremented past 0 it will be an out-of-bounds access. I...
  2. Replies
    2
    Views
    162

    #include #include ...

    #include <stdio.h>
    #include <stdlib.h>

    typedef struct Node
    {
    int data;
    struct Node *next;
    } Node;

    Node *AddNode(int data, Node *prev)
  3. Replies
    4
    Views
    202

    #include #include //...

    #include <stdio.h>
    #include <stdlib.h>

    // Print array a of size n on a single line.
    void print(int* a, int n)
    {
    for (int i = 0; i < n; i++)
    printf("%d ", a[i]);
    ...
  4. Of course. But I'm not sure I understand what you...

    Of course. But I'm not sure I understand what you mean. :confused:



    #include <stdio.h>

    int main()
    {
    printf("Hello\n"); // happens once, then never again
  5. Replies
    3
    Views
    140

    It really isn't very complicated. Asking the...

    It really isn't very complicated.
    Asking the user for the number of digits in the input number is not a good solution since the program can calculate that (which is what mag is for).
    Here it is...
  6. If you get rid of the break and let the loop...

    If you get rid of the break and let the loop condition stop the loop, then the loop increment will run once more so the final printf, after the loop, will need to print p - 1 (as in my second example...
  7. Replies
    3
    Views
    140

    Perhaps: #include typedef...

    Perhaps:


    #include <stdio.h>

    typedef unsigned long long ull;

    int main()
    {
    ull n;
  8. You need to learn to: * properly indent your...

    You need to learn to:
    * properly indent your code;
    * stop using goto (use while and for instead)
    * use arrays
    * use functions
    * don't flush(stdin)
  9. Replies
    49
    Views
    913

    pass

    pass
  10. #include #include int...

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

    int main ()
    {
    int nth_prime;
    printf("What prime number do you want to find: ");
    scanf("%d", &nth_prime);

    int p = 2;
  11. There is no "solved" marker. :cool:

    There is no "solved" marker. :cool:
  12. The entire standard library (libc) is available...

    The entire standard library (libc) is available by default. I believe the library option is -lc, but you don't need to manually add that.

    However, for historical reasons, the math library (libm)...
  13. Replies
    49
    Views
    913

    Using a bitmap is a pretty good idea. You could...

    Using a bitmap is a pretty good idea. You could store the numbers that way without converting to an int array. Then it's easy to compare to the drawn number to count matches.

    I set the code for...
  14. Replies
    49
    Views
    913

    The reason I didn't do it that way is to get the...

    The reason I didn't do it that way is to get the values in sorted order. I would change one thing in my original code, though, which is to use position 0 in the used array.


    void...
  15. Thread: Size_t problem

    by john.c
    Replies
    1
    Views
    113

    It's hard to understand what you are trying to...

    It's hard to understand what you are trying to do, but maybe:


    #include <stdio.h>
    #include <string.h>

    int main() {
    char s1[100], s2[100];
    printf ("Introduza duas strings: ");
    ...
  16. Replies
    49
    Views
    913

    #include #include #include...

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>

    #define NUM_TO_PICK 6
    #define HIGH_NUM 49

    void generate_ticket(int *ticket) {
    int used[HIGH_NUM + 1] = {0}; // initialized...
  17. Replies
    18
    Views
    259

    Neither gcc nor clang (with -std=c99 -Wall -W...

    Neither gcc nor clang (with -std=c99 -Wall -W -pedantic) gives an error or warning.


    // file1.c ///////////////////////////////
    #include <stdio.h>

    int Global_Variable;

    void...
  18. I didn't even think of boiling it down to a...

    I didn't even think of boiling it down to a single equation. That's pretty nifty. As written it will overflow at a lower value (49796), which I guess is an advantage of doing it in pieces. Your...
  19. Comparing the brute force and the smarter...

    Comparing the brute force and the smarter solution for an input of 4 billion:
    * the first does 4 billion additions to sum, 4 billion increments of i, 4 billion comparisons, and 4 billion jumps back...
  20. Replies
    15
    Views
    387

    I was able to recreate the problem and then fix...

    I was able to recreate the problem and then fix it again. :biggrin:
  21. Replies
    15
    Views
    387

    It is not in your interest to be a dick. I spent...

    It is not in your interest to be a dick.
    I spent the last 10 minutes finding the answer, but now I don't feel like posting it.
  22. Replies
    15
    Views
    387

    How about if you just use char instead of...

    How about if you just use char instead of unsigned char?

    (And you never said anything about trying it in a new project, so I asked.)
  23. Replies
    15
    Views
    387

    Doesn't seem possible, does it. Did you start a...

    Doesn't seem possible, does it.
    Did you start a new project, copy paste the code, and run it?
  24. Replies
    15
    Views
    387

    It should be: #include int...

    It should be:


    #include <iostream>

    int main() {
    std::cout << "12" << static_cast<unsigned char>(133) << "34" << '\n';

    // or
    std::cout << "12" << (unsigned char)(133) << "34"...
  25. Replies
    10
    Views
    308

    It ultimately stems from the fact that in a...

    It ultimately stems from the fact that in a multi-user machine, memory initially allocated to a new process is zeroed by the OS, lest it contain information from a previous process, possibly run by a...
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4