课程: Complete Guide to C Programming Foundations

今天就学习课程吧!

今天就开通帐号,24,100 门业界名师课程任您挑!

Chapter solution: Managing files

Chapter solution: Managing files

(bright music) - [Instructor] Here is my solution to the chapter challenge starting with the create_file function. The file name is passed as constant character f. It's opened at line 10, line 11 tests for an error. If so, an error message is output and the program quits. Otherwise, a success message is output at line 16. Remember to output the success messages, otherwise, the code runs quietly and the user may not think anything is happening. Line 19 writes my name to the file. The printf statement sends the text to the file, opened as file handle fh. Then a text message is output confirming the operation. The file is closed. Again, a text message outputs success. Your function need not read exactly as shown here, but it must contain all of the steps. To confirm that the file was written, the read file function reads in the string. A buffer is required, which is declared at line 30. You see, I use the same size 32, so I could have set this size as a constant. I chose not to. The file…

内容