Question: Please Help Me With This ASAP. UNIX C-Programming chunk.c #include #include #include #include #include #include int number_random_numbers = 1; int seed = 1; int verbose

Please Help Me With This ASAP.

UNIX C-Programming

chunk.c

#include #include

#include #include #include #include

int number_random_numbers = 1; int seed = 1; int verbose = 0; int help = 0; int linecounter = 1; int ccounter = 0; int wcounter = 0; char *name; char *pre; int suf;

void getCommanLine( int argc, char **argv ) { extern char *optarg; extern int optind; int ch;

if( argc > 10 ) fprintf( stderr, "usage: generate [-n ]%d ", argc );

while ( ( ch = getopt ( argc, argv, "l:w:c:f:p:s:" ) ) != EOF ) { switch ( ch ) { case 'l': { linecounter = atoi(optarg); linecounter++; printf(" Line counter '-l' is found which is %d ", linecounter); break; } case 'w': { wcounter = atoi(optarg); wcounter++; printf(" Word counter '-w' is found which is %d ", wcounter); break; } case 'c': { ccounter = atoi(optarg); ccounter++; printf(" Character counter '-c' is found which is %d ", ccounter); break; } case 'f': { name = optarg; printf(" Name of the '-f' file %s ", name); break; } case 'p': { pre = optarg; printf(" Name of prefix part '-p' file %s ", pre); break; } case 's': { suf = atoi(optarg); printf(" Name of the '-s' file %d ", suf); break; } default: { fprintf ( stderr, "%s: unrecognized option -%c ", argv[0], ch ); exit(1); break ; } } /* switch */ } /* while */ }

int my_getC( int input_fd ) { char buffer[1] ={'\0'}; int return_num_bytes_read;

return_num_bytes_read = read( input_fd, buffer, 1 ) ; if ( return_num_bytes_read == 0 ) { return EOF; } else if( return_num_bytes_read

// --------------------------------------------------------- // main() // --------------------------------------------------------- int main( int argc, char * argv[] ) {

getCommanLine( argc, argv ); // register int's is a hint to keep these integers // in registers for quick access. // // It not guaranteed that these requests to be // in registers are granted. // register int c, cc = 0, wc = 0, lc = 0;

int input_fd = STDIN_FILENO; // the input may be a file open file perhaps here? /* on the man page of read() found the page to open() using POSIX argc : number of counts of argumnets (will always be one) argv[0] : program itself for first argument argv[1] : taking the file or redirecting to a file " 1){ input_fd = open(argv[argc - 1], O_RDONLY); //taking the first argument (which file you want) and read only } while ( (c = my_getC( input_fd )) != EOF ) { ++cc; if( isgraph(c) ) // Checks for any printable character // except space (isgraph()). //ctype.h // // Check if the first part is a readable // word, will parse until the end of // the word { ++wc; // wc - word count is incremented do { // go until seeing a non printable // character (e.g., white space), unless it is EOF // then we would like to get out of there. c = my_getC( input_fd );

if( c == EOF ) // check for EOF { // goto statements are controversial. // it goes to label "done:" further below goto done; }

++cc; // character count is incrementd

} while ( isgraph(c) ); }

// not isgraph so check for a new line if (c == ' ') ++lc; // increment line count. }

//added different number of space compare to 8 to match the input correctly

//just to print done: printf( "%2d%3d%3d ", lc, wc, cc ); }

This is the question below

Please Help Me With This ASAP. UNIX C-Programming chunk.c #include #include #include

#include #include #include int number_random_numbers = 1; int seed = 1; int

You will implement the command chunk to divide a large file (filename.txt) into files of 1,000 lines each. At the UNIX shell prompt, your command should accept either: chunk [options] -f filename.txt [-p prefix] [-s suffix] chunk [options] [-p prefix] if an error occurs. Example: chunk -1 100 -f maria.txt -P part--s 00 Here chunk divides file maria.txt to new files named part-00, part-01, part02, ... that are each 100 lines long, except possibly the last file that may be less than 100 lines long. chunk -w 100 -f maria.txt -p part- -s 00 Here chunk divides file maria.txt to new files named part-00, part-01, parto2, ... that are each 100 words, except possibly for the last file that may be less than 100 words long. Other Requirements: The join the files back together again the cat command: cat part-00 part-01 part02 ... > maria2.txt should generate fle maria2.txt so that it is identical to the original maria.txt. The permissions of the output files should be the same as the permissions of the input file. You will implement the command chunk to divide a large file (filename.txt) into files of 1,000 lines each. At the UNIX shell prompt, your command should accept either: chunk [options] -f filename.txt [-p prefix] [-s suffix] chunk [options] [-p prefix] if an error occurs. Example: chunk -1 100 -f maria.txt -P part--s 00 Here chunk divides file maria.txt to new files named part-00, part-01, part02, ... that are each 100 lines long, except possibly the last file that may be less than 100 lines long. chunk -w 100 -f maria.txt -p part- -s 00 Here chunk divides file maria.txt to new files named part-00, part-01, parto2, ... that are each 100 words, except possibly for the last file that may be less than 100 words long. Other Requirements: The join the files back together again the cat command: cat part-00 part-01 part02 ... > maria2.txt should generate fle maria2.txt so that it is identical to the original maria.txt. The permissions of the output files should be the same as the permissions of the input file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!