Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

fopen for creation or modification

Status
Not open for further replies.

alzomor

Advanced Member level 2
Joined
Jun 9, 2005
Messages
674
Helped
39
Reputation
78
Reaction score
8
Trophy points
1,298
Location
Germany
Activity points
6,406
Hi

I need to open a text file .
if the file is not created I need to create it.
and if it's created I need to write within the file and not at the end


What mode should I use?

Salam
Hossam Alzomor
www(.)i-g(.)org
 

By the way which software are you using??
 

HI

we are using GNU C compiler under cygwin on Windows XP os

Salam
Hossam Alzomor
www(.)i-g(.)org
 

fopen("filename.txt","w");
 

false mode w
w Create for writing. If a file by that name already exists, it will be overwritten.

is better

Code:
      FILE *fp;
      
      fp=fopen("filename.txt","r+");  //Open an existing file for update (reading and writing).
      if(fp==NULL)  //If a file by that name NO exists!!....Create
      {
            fclose(fp);
             fp=fopen("filename.txt","w");
       }

//insert code here



//no forget
fclose(fp);
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top