From the course: C Standard Library

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Copying a text file

Solution: Copying a text file - C Tutorial

From the course: C Standard Library

Start my 1-month free trial

Solution: Copying a text file

(upbeat music) - Let's take a look at this solution to the problem, and this is how we'll do it. First I will guide you through the code so that you can understand how I'm using the functions, and next I will create a new file, and write some text in it so that I can run the application, and show you how it was successfully copied. So let's get started. As you can see, I only have one main function starting at line three, and the first thing I do is declare two strings. One is called source. The next one is called target, and they are both 50 characters long. So in line six, I am asking the user for a source file name with a print F function call. And next, in line seven, I am using scan F to get that string into source. I'm doing the same in lines eight and nine for the target file name. Now, in lines 11 and 12, that's where I'm creating the file descriptors with F open, and I am using the source and target file names respectively, but notice how, in line 11, I am using the R access…

Contents