Search:

Type: Posts; User: john.c

Page 1 of 20 1 2 3 4

Search: Search took 0.02 seconds.

  1. Here's an example of a working program without...

    Here's an example of a working program without any optimizations except for only checking divisors up to the square root. Note that it's easy to only check odd numbers by dealing with 2 separately.
    ...
  2. Replies
    9
    Views
    226

    No problem. Note that you didn't use the fgets...

    No problem. Note that you didn't use the fgets followed by *scanf idiom correctly. The *scanf shouldn't have been an fscanf but an sscanf, taking input from the line you read with fgets. One good...
  3. Replies
    9
    Views
    226

    Since you've already read through the whole file...

    Since you've already read through the whole file to determine the number of lines, you need to reset it back to the beginning to read the numbers. You can close it and re-open it, use fseek, or use...
  4. Replies
    7
    Views
    341

    Yes, the reasonable implementation-defined...

    Yes, the reasonable implementation-defined options for a right-shift would be whether it is "arithmetic" or "logical". I'm aware that it works in either case in your situation, but I don't understand...
  5. Replies
    7
    Views
    341

    Since pointers are obviously unsigned integers it...

    Since pointers are obviously unsigned integers it seems logical to store it in an unsigned integer.

    At any rate, right-shifting a signed integer with a negative value (high bit set) is...
  6. Replies
    7
    Views
    341

    Sounds good. Make sure it's an unsigned long,...

    Sounds good. Make sure it's an unsigned long, though. I should have used an unsigned long long in the code I posted. Note that, technically, long is not guaranteed to be 64 bits, although it almost...
  7. Replies
    7
    Views
    341

    #include #include #include...

    #include <stdio.h>
    #include <stdint.h>
    #include <inttypes.h> // this includes stdint.h, too

    int main()
    {
    void *p = &p; // holds address of itself

    // The usual way.
    ...
  8. Replies
    6
    Views
    328

    I forgot to reset the variable arguments for the...

    I forgot to reset the variable arguments for the vfprintf call. It should be:


    void print(const char *fmt, ...) {
    va_list va;
    va_start(va, fmt);

    vprintf(fmt, va);
    ...
  9. Replies
    6
    Views
    328

    _exit() doesn't flush open file buffers. exit()...

    _exit() doesn't flush open file buffers. exit() does.
    You may wish to flush after every line.
    Instead of writing all output twice you could use a function like this:


    void print(const char...
  10. In the 4238-line file, make sure that there is...

    In the 4238-line file, make sure that there is not an extra space before or after the word senator.
  11. I notice that you forgot to initialize k to 0...

    I notice that you forgot to initialize k to 0 before filling your jobs array (which would be better named "jobs" instead of the meaningless "arr"). You are also not testing for end-of-file correctly....
  12. I don't use Windows but maybe you need to...

    I don't use Windows but maybe you need to GlobalFree(hData) before the function returns. And you don't need the double pointer.
    Untested:


    #include <windows.h>
    #include <stdio.h>
    #include...
  13. Replies
    4
    Views
    450

    Think again.

    Think again.
  14. Replies
    1
    Views
    335

    You aren't calling the function, just...

    You aren't calling the function, just "mentioning" the function name, which does nothing.


    #include <stdio.h>

    void foo()
    {
    printf("X\n");
    }
  15. Replies
    4
    Views
    450

    I don't know the problem, but I think it's better...

    I don't know the problem, but I think it's better written like this:


    #include <avr/io.h>
    #include <util/delay.h>

    int main()
    {
    while (1)
    {
  16. Replies
    1
    Views
    259

    wordCountChoice should be an integer, not a char*...

    wordCountChoice should be an integer, not a char* if that's what it is.
    You can convert the string input to an integer with atoi().
    Also note that line 2 above does nothing.
  17. Replies
    9
    Views
    703

    I looked at the generated assembly (with -S) and...

    I looked at the generated assembly (with -S) and it has unrolled the loop, but only for 3 iterations. However, just using -funroll-loops doesn't cause the problem.
  18. Replies
    9
    Views
    703

    -Og enables optimizations that do not interfere...

    -Og enables optimizations that do not interfere with debugging.
    It would not include unrolling loops, which is at least part of what's happening here, albeit incorrectly.
  19. Replies
    9
    Views
    703

    Very strange. You can even start c at 1000....

    Very strange. You can even start c at 1000. Interesting how changing unsigned to int fixes it.


    #include <stdio.h>

    int main()
    {
    unsigned a, b, c = 1000;

    for (a = 0; a < 5; ++a)
  20. The point is that you didn't mention the other...

    The point is that you didn't mention the other post in your question. Someone might have wasted their time helping you when you had already received an answer at the other site.

    BTW, it seems that...
  21. Replies
    17
    Views
    1,449

    That's idiotic. You should crank it up at least...

    That's idiotic. You should crank it up at least as high as -Wall -Wextra -Wpedantic. In fact you can add more, such as -Wshadow to detect shadowing a variable, a common beginner mistake (although...
  22. Don't try to debug the windows header files!...

    Don't try to debug the windows header files!
    Presumably you forgot to include <windows.h> or something.
    If GUID is defined, then the definitions you are missing are:


    typedef GUID IID;
    typedef...
  23. Thread: Unions...

    by john.c
    Replies
    8
    Views
    1,023

    If that's true then why did you show something...

    If that's true then why did you show something different?
  24. Replies
    37
    Views
    2,558

    I doubt that very much. You are clearly a...

    I doubt that very much. You are clearly a braindead moron. :cool:
  25. x is supposed to be an integer, and presumably...

    x is supposed to be an integer, and presumably positive even though it doesn't specify.
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4