The code program that writes characters to a file when learning C.
* * File: main.c
* Author:wuguowei
*
Created on February 12, 2015, Morning 11:54 *
*
#include < stdio.h>
#include <stdlib.h>
*
*
/int main (int argc, char** argv) {
char * FilePath = "/home/wuguowei/netbeansprojects/studydemo/result";
char ch;
FILE *FP;
while (fp = fopen (FilePath, "w") = = NULL) {
printf ("Cannot open file \ n");
Exit (0);
}
ch = getchar ();
printf ("Please enter a string to be stored in the file \ n");
ch = getchar ();
while (ch!= ' # ') {
FPUTC (CH, FP);//write File
putchar (CH);//output to screen
ch = getchar ();
}
Fclose (FP);
Putchar (ten);
return exit_success;
}
Type a carriage return, and then enter the contents as follows:
* * File: main.c
* Author:wuguowei
*
Created on February 12, 2015, Morning 11:54 *
*
#include < stdio.h>
#include <stdlib.h>
*
*
/int main (int argc, char** argv) {
char * FilePath = "/home/wuguowei/netbeansprojects/studydemo/result";
char ch;
FILE *FP;
while (fp = fopen (FilePath, "w") = = NULL) {
printf ("Cannot open file \ n");
Exit (0);
}
ch = getchar ();
printf ("Please enter a string to be stored in the file \ n");
ch = getchar ();
while (ch!= ' # ') {
FPUTC (CH, FP);//write File
putchar (CH);//output to screen
ch = getchar ();
}
Fclose (FP);
Putchar (ten);
return exit_success;
}