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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

how to write character to a file?

Reply to Message Icon

Name: Jack Bram
Date: November 24, 2002 at 09:43:05 Pacific
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();
}




Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: November 24, 2002 at 10:34:14 Pacific
Reply:

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.


0
Reply to Message Icon

Related Posts

See More


JBuilder ? Data validation in VB



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: how to write character to a file?

Writing to a file in C www.computing.net/answers/programming/writing-to-a-file-in-c/10521.html

Writing to a file from Xcopy www.computing.net/answers/programming/writing-to-a-file-from-xcopy/13152.html

Saving to a file MFC www.computing.net/answers/programming/saving-to-a-file-mfc/8994.html