Search:

Type: Posts; User: john.c

Page 1 of 20 1 2 3 4

Search: Search took 0.01 seconds.

  1. As usual, I don't understand what you are trying...

    As usual, I don't understand what you are trying to do. The code doesn't make sense to me and you've never really been able to explain what in the world you are trying to do overall. I'm lost. It's...
  2. I didn't test it and forgot some closing...

    I didn't test it and forgot some closing double-quotes.
    But you put them in the wrong place.
    Note that you should probably use _pclose to close a FILE* opened with _popen.


    FILE* dns =...
  3. It may have been overly-complicated (showing two...

    It may have been overly-complicated (showing two different ways and using inttypes).
    How about this.


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

    int main()
    {
    FILE *in = fopen("input.txt",...
  4. #include #include #include...

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

    #define FRM_SCN "%" SCNu32 ".%" SCNu32 ".%" SCNu32 ".%" SCNu32
    #define FRM_PRI "%" PRIu32 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32
    ...
  5. I didn't realize that the input was restricted to...

    I didn't realize that the input was restricted to 0 to 10.
    In that case it will sort of work, but it's an incredibly stupid idea.
  6. You really need to improve your spacing. You...

    You really need to improve your spacing.

    You seem to be trying to return the fib through the program's exit status.
    That's not going to work.


    #include <stdio.h>
    #include <stdlib.h>...
  7. Replies
    5
    Views
    142

    I wouldn't put it quite like that. But if a...

    I wouldn't put it quite like that.
    But if a calculation can be done at compile time then that's when it will usually be done (at least with optimizations).
    So if you say printf("%d\n", 2 * 3 * 4)...
  8. The return value from main is different from...

    The return value from main is different from return values from other functions.
    Main's return value is called the program's "exit status".
    It is non-portable to use this value for anything but...
  9. Replies
    5
    Views
    142

    There should be no difference in this case since...

    There should be no difference in this case since 'sizeof(struct _menu_item)' is constant, so nothing needs to be "calculated" at run-time since it's done at compile time.
  10. So what should we enter for "size" and...

    So what should we enter for "size" and "seconds"???

    And look at lines 168 and 169 above.
    Array indices start at 0, and the max index for a 3-element array is 2.
  11. Replies
    9
    Views
    396

    That's because the first discrepancy in the two...

    That's because the first discrepancy in the two strings is between the last '1' of the first string and the terminating '\0' of the second string, the difference of their ascii codes being 49 since...
  12. Replies
    9
    Views
    396

    Jim has made a rare error here, simply comparing...

    Jim has made a rare error here, simply comparing the addresses of the string literals and not their "values":


    std::cout << "Are the strings equal: " << std::boolalpha << ("1 222 111" == "1...
  13. Replies
    2
    Views
    119

    It's a meaningless question since you haven't...

    It's a meaningless question since you haven't told us what your command line parameters were.
  14. Replies
    10
    Views
    243

    Note that there is an error in the last part of...

    Note that there is an error in the last part of the code you've quoted. I fixed it in the original (it should've used strlen instead of sizeof since Delim is just a pointer).
    BTW, you don't need to...
  15. Replies
    10
    Views
    243

    So maybe something like this then: int...

    So maybe something like this then:


    int get_response_time(const char *ip)
    {
    char cmd[64];
    printf("Pinging %s...\n", ip);
    sprintf(cmd, "./ping %s", ip);
    int ms = -1;
    FILE...
  16. Replies
    10
    Views
    243

    If the numbers you want to compare are in strings...

    If the numbers you want to compare are in strings like these:


    char s[] = "Media = 234ms";
    char t[] = "Media = 99ms";

    Then comparing with strcmp will show t as being greater than s...
  17. Replies
    10
    Views
    243

    You might be able to do something like this. The...

    You might be able to do something like this. The %*[^0-9] scanf format spec will skip and discard non-digits. %d will then read the integer starting at that point.


    #include <stdio.h>

    int...
  18. Replies
    10
    Views
    243

    To compare strings you need to use strcmp. ...

    To compare strings you need to use strcmp.


    int result = strcmp(target, target2));
    if (result < 0) printf("DNS1 better\n");
    else if (result > 0) printf("DNS2 better\n");
    else ...
  19. Yes, that is commonly done. The trick is that...

    Yes, that is commonly done. The trick is that consecutive string literals, separated by only whitespace (incl. newlines) are "pasted" together into one string literal.


    #define BASE_PATH ...
  20. Replies
    29
    Views
    1,178

    void scan_ipconfig() { const char *terms[] =...

    void scan_ipconfig() {
    const char *terms[] = {
    "IPv4",
    "subred",
    "Puerta",
    "Servidores DNS",
    NULL
    };
    FILE *f = popen("ipconfig...
  21. Replies
    29
    Views
    1,178

    Maybe try something like this. void...

    Maybe try something like this.


    void ping(const char *ip) {
    char ping_cmd[256];
    sprintf(ping_cmd, "ping %s", ip);
    FILE *f = popen(ping_cmd, "r"); // popen is a posix function
    ...
  22. #include int main() { char...

    #include <stdio.h>

    int main() {
    char buffer[1024] = "12 123 1 1234 21 2 321 32\n";
    int n[8];

    char *pbuf = buffer;
    for (int i = 0, pos = 0; i < 8; ++i)
    sscanf(pbuf...
  23. Note that scanf("%c", &a[i]); will read the very...

    Note that scanf("%c", &a[i]); will read the very next character, even if it's a space, tab, or newline. If you want to skip whitespace, put a space before the %c:


    scanf(" %c", &a[i]);
  24. Replies
    11
    Views
    243

    It's storing the string data as "immediate" data....

    It's storing the string data as "immediate" data.

    7935471345745880427 decimal is, in hex, with associated ascii-per-byte:


    6E 20 75 25 20 79 65 6B
    n u % y e k

    which is "key...
  25. Replies
    6
    Views
    261

    Here's an example that redirects the standard...

    Here's an example that redirects the standard streams like you were trying to do.
    Note that you can use stderr to print the parent's prompt since stderr is still going to the terminal.


    #include...
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4