Method 1: #include main () {file * fp; int i = 0; char * s = "am i right?"; Fp = fopen ("c: //text.txt", "WR "); While (* s) {printf ("% c ", * s); fseek (fp, i , seek_set); fPrintf (fp,"% c ", * s );} fclose (fp); getchar ( } Method 2: #include #include #include main () {file * fp; char ch; fp = fopen ("f: //file.txt "," WB "); // Write open files, you change file.txt to your own files OK if (fp == null) {Printf (" can't open file.txt / n ") EXIT (1);} // Open file failed to exit Scanf ("% C", & ch); while (ch! = '*') // input character * exits {printf ("% c / n", CH); FPUTC (CH, FP); // Write CH to the file fflush (stdin) that you open; // Clear the input buffer Scanf ("% C", & ch); // Continue to enter a character} Printf "Input over! / n"); getCh ();} method three: #include #include
Void Xprintf (const char * pszformat, ...) {char Buf [1024] = {0}; file * cfptr = fopen ("1.log", "a"); va_list arg_ptr; va_start (arg_ptr, pszformat); vSprintf (buf, pszformat, arg_ptr); VA_END (ARG_PTR); Printf ("% s", buf); if (cfptr! = null) {fprintf (CFPTR, "% s", buf); fclose (cfptr);} }
INT Main (int Argc, char * argv []) {xprintf ("% - 10d% s / n", 99, "hello world"); return 0;} method four: void writedat (void) {INT i;
Char XX [2] [23] = {"You HE Me", "I am A student."}; // test data. File * fp;