Search command output for string
Hi,
I'm very new to C programming.
What I'm attempting to do is to run a command in Windows and then parse the output of that command for a specific string of characters. Here is the code that I have working--it simply prints the output of the command.
Code:
#include <stdio.h>
int main()
{
FILE *fp;
char path[1035]; // Set path array size to 1035.
fp = popen("ipconfig", "r"); // Open the command.
if(fp == NULL) { // If nothing is returned, error out.
printf("Failed to run command\n");
}
while(fgets(path, sizeof(path) - 1, fp) != NULL) { // Get output from command and print it.
printf("%s", path);
}
pclose(fp);
return 0;
}
What I'd like this program to do is parse the output of that command (rather than print it), searching for specific IP addresses. If it finds the searched-for IP address(es), I would like it to print those values. As yet, I have been unable to do this.
Any pointers would be greatly appreciated!
~ Tom