#include #include #include #include #include #include //This demo gets command line arguments, then uses those arguments to // open a file and read the first 20 bytes. int main( int argc, char* argv[] ){ if( argc < 5 ){ printf("Error you did it wrong\n"); return 0; } char* inFile = argv[1]; char* outFile = argv[2]; int run_length = atoi( argv[3] ); int mode = atoi( argv[4] ); printf("Input file: %s\n", inFile ); printf("Output file: %s\n", outFile ); printf("Run length: %d\n", run_length ); printf("Mode: %d\n", mode ); int inFD = open( inFile, O_RDONLY ); int outFD = open( outFile, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR ); const int buffer_size = 7; char buffer [buffer_size + 1]; //Extra byte for a null terminator ssize_t ret_val; while( 1 ){ ret_val = read(inFD, buffer, buffer_size); if( ret_val == -1 ){ perror("Could not read from file: "); //printf("Read error\n"); break; } if( ret_val == 0 ){ //End of file break; } //Null terminate the buffer buffer[ret_val] = '\0'; printf("%s", buffer ); } return 0; }