Thread: System I/O

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    115

    System I/O

    Hello

    I am trying to open 2 inputfiles and create 1 outputfile.
    This outputfile will be a concatenation of the 2 inputfiles.

    I want to copy the first file to the outputfile but when i try to read the outputfile I get an error : U dont have permission to open the document ......

    Is there someone who knows the problem?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <fcntl.h>
    #include <sys/stat.h>
    #include <unistd.h>
    
    #define BUFSIZE 512
    char buff[BUFSIZE];
    
    int main (int argc, char *argv[]){
    
    	int file1, file2, output;
    	int bytes;
    
    	if (argc != 4){
    		perror("ERROR");
    		exit(0);
    	}
    
    	if ((file1 = open(argv[1], O_RDONLY)) < 0){
    		perror("ERROR");
    		exit(0);
    	}
    
    	if ((file2 = open(argv[2], O_RDONLY)) < 0){
    		perror("ERROR");
    		exit(0);
    	}
    
    	if ((output = open(argv[3], O_CREAT | O_WRONLY| S_IWRITE)) < 0){
    		perror("ERROR");
    		exit(0);
    	}
    
    	while ((bytes = read(file1, buff, BUFSIZE)) > 0)
    		write(output, buff, BUFSIZE);
    	
    	return 0;
    }

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by thescratchy View Post
    Code:
    	if ((output = open(argv[3], O_CREAT | O_WRONLY| S_IWRITE)) < 0){
    Should be

    Code:
    	if ((output = open(argv[3], O_CREAT | O_WRONLY, S_IWRITE)) < 0){
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    115
    k ty, but it still doesnt work

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Quote Originally Posted by thescratchy
    I get an error : U dont have permission to open the document ......
    Why don't you post the actual error message? Is there anything else you're saying/not saying that isn't accurate? The code (after the fix by brewbuck) seems to work fine for me. Do you have permission to read/write the various files? Verify the 2 files can be read, and that you have permission to write to wherever you're specifying.

  5. #5
    Registered User
    Join Date
    Feb 2010
    Posts
    115
    Yes i have permission to read the input files. They are just on my desktop
    and i am writing the output file also to my desktop.

    When i try and open the output file, i get an error :

    U heeft geen toestemming om het document 'concat.txt"' te openen.
    Vraag uw computer of netwerkbeheerder om assistentie.

    Translation:

    U dont have permission to open the file.
    Ask help at your networkmanger.

    I am using mac btw.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Oh, you mean read with an editor, not like read the file in the program.

    Quote Originally Posted by http://www.warpspeed.com.au/cgi-bin/inf2html.cmd?..\html\book\Toolkt40\XPG4REF.INF+205
    S_IWRITE Writing permitted

    S_IREAD Reading permitted
    When you create the file its only given "write" permissions, you probably want to give it (at least) also "read" permissions.

  7. #7
    Registered User
    Join Date
    Feb 2010
    Posts
    115
    Yes, that is indeed the problem. TYVM

    I thaught that the S_IREAD, S_IWRITE were used to read and write in your c program.
    Thanx for the clarification

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File System Implementation
    By dodgeviper in forum C Programming
    Replies: 9
    Last Post: 11-16-2007, 01:04 PM
  2. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 07:56 PM
  3. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  4. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  5. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 07:12 AM