Computing.Net > Forums > Programming > how to write character to a file?

how to write character to a file?

Reply to Message Icon

Original Message
Name: Jack Bram
Date: November 24, 2002 at 09:43:05 Pacific
Subject: how to write character to a file?
OS: Win2000
CPU/Ram: 160MB
Comment:

ok, I know how to creat a new file,
but how do i write characters to this file?


FILE fp;

fp = fopen("filename", "w");
if (fp == NULL) {
/* the open failed */
exit();
}



Report Offensive Message For Removal

Response Number 1
Name: Don Arnett
Date: November 24, 2002 at 10:34:14 Pacific
Subject: how to write character to a file?
Reply: (edit)

Sounds like you need to buy a C book or find a tutorial (try www.tutorgig.com). It'll take you forever asking about one statement at a time.

There are numerous functions that will output to a file.

fprintf() works just like printf() except that you add 'fp' as the first parameter:

fprintf(fp, "%s\n", "some string);


I believe putc() is the file version to output a single character. It's probably:

putc(fp, 'c');

but I haven't used it in a while. You should be able to look it up as easily as I.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: how to write character to a  file?

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software