do either through cmd redirection using > operator like yourprogram.exe>file.txt or using the file handling concept of c
Code: c
FILE *fp;

fp = fopen("file.txt","ab+");
//this opens file handling mode
 
Now use various file output functions available in C to write what you want in to the text file.