Change the file extension using C

dearimranz's Avatar, Join Date: Jan 2008
Newbie Member
Hi there,

I am working on a project where I need to change the extension of file using C. For example I want to change a ".dat" file and write it in the form of ".txt" file.

Can someone help me with this. I will be very thankful.

,,,
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Moved to C-C++ forum for better response.
Salem's Avatar, Join Date: Nov 2007
Ambitious contributor
C doesn't care about file extensions.

Code:
FILE *in = fopen("file.dat","rb");
FILE *out= fopen("file.txt","w");
Then you can do whatever you want to read from the .dat file, and write to the .txt file.