Search:

Type: Posts; User: john.c

Page 1 of 20 1 2 3 4

Search: Search took 0.02 seconds; generated 30 minute(s) ago.

  1. A simple example: #include ...

    A simple example:


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

    char *mult(const char *a, const char *b) {
    int alen = strlen(a), blen = strlen(b);
    char *c =...
  2. The 509 limit is C89's limit for string literals,...

    The 509 limit is C89's limit for string literals, not arrays. It's raised to 4095 in C99. Implementations are likely to set it much higher or make it unlimited.

    A char array would presumably have...
  3. Try replacing lines 58 and 59 with this: ...

    Try replacing lines 58 and 59 with this:


    if (text.format != 8)
    printf("bad format\n");
    else {
    char *v = text.value;
    while (*v) {
    if (strcmp(v,...
  4. Replies
    3
    Views
    182

    The final condition definitely doesn't make sense.

    The final condition definitely doesn't make sense.
  5. For a quick fix to returning a local you could...

    For a quick fix to returning a local you could make mul static.
    Better still, return a malloc'ed string.
    MAX should be a define.

    In your for (i = lb; i >= 0; i--) loop, k is going way out of...
  6. Replies
    7
    Views
    354

    Take a look at the source code for killall5...

    Take a look at the source code for killall5 (which pidof actually runs; note line 1021 which passes control to the function main_pidof).
    sysvinit/killall5.c at master * limingth/sysvinit * GitHub
    ...
  7. Replies
    1
    Views
    404

    "data" will never be NULL, so you can't use it to...

    "data" will never be NULL, so you can't use it to detect a sublist. You need a separate type member.
  8. 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.
    ...
  9. Replies
    11
    Views
    456

    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...
  10. Replies
    11
    Views
    456

    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...
  11. Replies
    7
    Views
    451

    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...
  12. Replies
    7
    Views
    451

    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...
  13. Replies
    7
    Views
    451

    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...
  14. Replies
    7
    Views
    451

    #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.
    ...
  15. Replies
    6
    Views
    418

    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);
    ...
  16. Replies
    6
    Views
    418

    _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...
  17. 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.
  18. 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....
  19. 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...
  20. Replies
    4
    Views
    464

    Think again.

    Think again.
  21. Replies
    1
    Views
    356

    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");
    }
  22. Replies
    4
    Views
    464

    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)
    {
  23. Replies
    1
    Views
    281

    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.
  24. Replies
    9
    Views
    750

    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.
  25. Replies
    9
    Views
    750

    -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.
Results 1 to 25 of 499
Page 1 of 20 1 2 3 4