Question
Please help me fast asap. please I want output like this when input has given below in input.txt file output.txt MoMakoke mome a sosanondodwowicochoh. WoWhohatot?
Please help me fast asap. please
I want output like this when input has given below in input.txt file
output.txt
MoMakoke mome a sosanondodwowicochoh. WoWhohatot? MoMakoke itot yoyourorsoselolfof. SoSudodo momakoke mome a sosanondodwowicochoh. Okokayoy.
input.txt
Make me a sandwich. What? Make it yourself. Sudo make me a sandwich. Okay.
main.c
#include
#include
#define D_BUFSIZE 1 /* size of buffer for input and output */ /* should be a block size, 512, 4096, 8192 */
#define NUM_ARGS 4 /* required number of command line arguments */
#define ERROR_ARGS 1 #define ERROR_OPEN_R 2 #define ERROR_OPEN_W 3 #define ERROR_WRITE 4 #define ERROR_CALLOC 5
#define SUCCESS 0 #define ERROR -1
int BUFSIZE = D_BUFSIZE;
int main( int argc, char * argv[] ) { int input_fd, output_fd; /* file descriptors for i/o */ ssize_t return_num_bytes_write, /* number of bytes returned from write() */ return_num_bytes_read; /* number of bytes returned from read() */ char *buffer; /* character buffer -not allocated */ char *fn = strdup("filecopy");
/* allocates memory a character buffer */ /* calloc initializes the buffer to all 0s */ buffer = ( char * ) calloc( BUFSIZE, sizeof(char)); if( buffer == NULL ) { /* perror prints a system error message along the argument */ perror( "calloc" ) ; return ERROR_CALLOC ; }
/* HINT 2 (can useful for Q2: allocate space for a constant * string you can use strdup(). * Example USAGE: * #include
/* Create user level read file descriptors */ /* use the first argument on input line as the name the file */ /* open it in Read Only - Mode - O_RDONLY */ /* more info on open : http://man7.org/linux/man-pages/man2/open.2.html */ /* or http://linux.die.net/man/2/open = not sure abou die.net but it */ /* loads really quicly! */ /* when successful - open returns the lowest numbered file descriptor */ /* not currently open for the process (this running program). */ input_fd = open( "input.txt", O_RDONLY ); if( input_fd == ERROR ) { /* perror prints a system error message along the argument */ perror( "open" ) ; return ERROR_OPEN_R; }
/* Create user level write file descriptors */ /* write only, create it if it doen't excist, and RW owner, read others */ output_fd = open( "output.txt", O_WRONLY | O_CREAT, 0644 ); if( output_fd == ERROR ) { perror( "open" ) ; return ERROR_OPEN_W; }
while( /* read returns characters read, then this value is checked to * see if it is greater than 0, if not breaks out of the loop */ (return_num_bytes_read = read( input_fd, buffer, BUFSIZE )) > 0 ) /* while parenthesis */ { return_num_bytes_write = write ( output_fd, buffer, (ssize_t) return_num_bytes_read ); if( return_num_bytes_read != return_num_bytes_write ) { perror("write"); return ERROR_WRITE; } }
/* Close file descriptors */ close( input_fd ); close( output_fd ); return SUCCESS; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started