Can this be done?

This is a discussion on Can this be done? within the C Programming forums, part of the General Programming Boards category; How would you write this code using C stdio library routines instead of the UNIX kernel routines? Code: #include <stdio.h> ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    6

    Can this be done?

    How would you write this code using C stdio library routines instead of the UNIX kernel routines?

    Code:
    #include <stdio.h>
    #include <fcntl.h>
    intmain()
    {
       int inFile, outFile;
       char *inFileName = "in_test";
       char *outFileName = "out_test";
       int len;
       char c;
    
       inFile = open(inFileName, O_RDONLY);
       outFile = open(outFileName, O_WRONLY);
     /* Loop through the input file */
       while((len = read(inFile, &c, 1)) > 0)
       write(outFile, &c, 1);
    /* close files and quit */
       close(inFile);
       close(outFile);
    }
    Thanks for your help.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    fopen() instead of open()
    fclose() instead of close()
    fwrite() instead of write()
    fread() instead of read()

  3. #3
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    and probably

    "r" instead of O_RDONLY
    "w" instead of OWRONLY

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21