Thread: Trapped between conditionals and booleans

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2020
    Posts
    39

    Trapped between conditionals and booleans

    Hey, so I'm about to finish my damn task with IP pings and whatnot! Thanks a lot for your support, guys. But now, while trying to improve one of my modules, just found out how useless I'm trying to cope with conditionals and booleans. It looks like this:

    Code:
    // Process to find a substring between two strings in order to attain a certain digit.
        fp = fopen("dns1.txt", "r");
        while (fgets(line, sizeof(line), fp))
            if (start = strstr(line, PATTERN1))
            {
                start += strlen(PATTERN1);
                if (end = strstr(start, PATTERN2))
                {
                    target = (char*)malloc(end - start + 1);
                    memcpy(target, start, end - start);
                    target[end - start] = '\0';
                }
            }
    
        // Printing the result of DNS 1
        if (target) printf("\n\n    Medium value for DNS1 %s", target);
        else printf("\n    DNS 1 shows error of connectivity");
    
    ...
    
        // Comparing both DNS.
        if (target < target2) (comparing a time of response, that's why < equals actually better)
            printf("\n\n    DNS 1 is better than DNS 2.");
        else if (target > target2)
            printf("\n\n    DNS 2 is worse than DNS 1.");
        else if (target == target2)
            printf("\n\n    Both coincide.");
        else printf("\n\n    There was an error.");
    Now what I want to do:
    I'd like to fix those bold parts. I mean, if I cannot find such substring in the output .txt file I'm accessing, that would return false and print the second printf (that else if).

    If I got true (i.e., that substring was found), store it as variable target and print the first sentence (Medium value for DNS1 %s).

    Then, I'd like to aitoi it to make it an integer. No worries for that part at all (even though I've gotten my share of compiling and runtime errors, but I guess it just had to do with the previous and following part).

    If DNS 1 and DNS 2 got me true in both cases (DNS1 = true && DNS2 = true), so to speak, compare them. If one of them fails (DNS1 = false || DNS2 = false), print an error.

    So far I'm having bad luck with else... statements, which get printed all along during the execution of a certain read or ping.

    Thanks in advance for your time and attention once again...
    Last edited by JSteel; 05-08-2020 at 02:27 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. conditionals
    By s_siouris in forum C Programming
    Replies: 3
    Last Post: 03-11-2008, 07:29 AM
  2. Help plz, Booleans
    By tagman in forum C++ Programming
    Replies: 2
    Last Post: 07-26-2005, 08:30 AM
  3. Booleans in C
    By KneeLess in forum C Programming
    Replies: 6
    Last Post: 09-09-2004, 09:47 AM
  4. Conditionals
    By uniqueniq in forum C Programming
    Replies: 6
    Last Post: 02-13-2003, 06:20 PM
  5. booleans
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 03-10-2002, 12:01 PM

Tags for this Thread