/* 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;
}
Tuesday, February 10, 2015
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment