C:/>netsh interface show interface
Admin State State Type Interface Name
-------------------------------------------------------------------------
Disabled Disconnected Dedicated Wireless Network Connection 2
Disabled Disconnected Dedicated Local Area Connection 2
Enabled Connected Dedicated Wireless Network Connection
Enabled Disconnected Dedicated Local Area Connection
I want to write a C program which will only store "Interface Name" in an array, for example the output should be like
array=['Wireless Network Connection 2','Local Network Connection 2',
'Wireless Network Connection','Local Network Connection']
I wrote a simple program to achieve this, but I'm not getting any suitable output.
NOTE: In the code, I am just printing the required data instead of storing it in an array.
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
int main(){
//FreeConsole();
system("netsh interface show interface > output.txt");
FILE *fp;
fp = fopen("output.txt","r");
char line[256];
while(fgets(line, sizeof(line), fp)){
printf("==> %s", line);
int i = 0;
char *p = strtok(line," ");
while(p != NULL){
printf("%s\n", p);
p = strtok(NULL, " ");
}
}
fclose(fp);
getch();
return 0;
}