Search code examples
csystem

How to store strings from system function


I would like to know if there is a way to store the things that system prints out when you call some function from it for e.g. i want my program to read my Wi-Fi key/everything that comes out of console and store it in a .txt file.Is that possible? If not is printing out strings from system possible?

Here is the code for printing out the contents:

#include <stdio.h>


int main()
{
    system("netsh wlan show profile wifi name key=clear");



    return 0;
}

Solution

  • I figured it out using a much simpler way than @Ratul Sharker and @Basile Straynkevitch suggested. The solution is using > in the system, but you must have a .txt file before compilation(might figure out a way for the program to write the file)

    Code:

    #include <stdio.h>
    
    
    int main()
    {
        system("netsh wlan show profile wifi name key=clear > C:\\somepath\\name.txt");
    
    
    
        return 0;
    }