Thread: Can this be done?

  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,268
    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