Open the text file, *file, in write mode, return a FILE pointer or NULL if opening the file failed. To open the file in read mode, use fopenRT(), and for binary files, replace the R with W. For read/write, use fopenM().
FILE *fp = fopenWT("c:\\temp\\txtfile.txt");
if (fp == NULL)
warning("Failed to open output file.");