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...