Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

fopen for creation or modification

Status
Not open for further replies.

alzomor

Advanced Member level 2
Joined
Jun 9, 2005
Messages
678
Helped
39
Reputation
78
Reaction score
8
Trophy points
1,298
Location
Cairo
Activity points
6,417
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
 

nandhu015

Advanced Member level 5
Joined
Feb 11, 2006
Messages
1,965
Helped
300
Reputation
600
Reaction score
224
Trophy points
1,353
Location
India
Activity points
9,816
By the way which software are you using??
 

alzomor

Advanced Member level 2
Joined
Jun 9, 2005
Messages
678
Helped
39
Reputation
78
Reaction score
8
Trophy points
1,298
Location
Cairo
Activity points
6,417
HI

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

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

mayavi

Junior Member level 3
Joined
Sep 6, 2009
Messages
27
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
ind
Activity points
1,419
fopen("filename.txt","w");
 

aospinas

Member level 2
Joined
Nov 24, 2003
Messages
53
Helped
10
Reputation
20
Reaction score
3
Trophy points
1,288
Activity points
226
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

Top