Tuesday, February 10, 2015

Writing A File

/* Create a program in C to write to a file */ #include <stdio.h> int main() { char fname[20]; printf("Enter the name of the file to write: "); scanf("%s", fname); FILE *fp; char ch; fp=fopen(fname, "w"); printf("Enter data to be stored in to the file, enter # to stop:\n"); while((ch=getchar())!='#') putc(ch, fp); fclose(fp); printf("\nFile written, press any key to exit.\n"); getch(); return 0; }

Share

& Comment

0 comments:

Post a Comment

 

Copyright © 2015 Code Fervor™ is a registered trademark.

Designed by Templateism By Naman Kumar