Write a C program, uni.c, which reads a given file using Unix open()/read() system calls as well
Question:
Write a C program, uni.c, which reads a given file using Unix open()/read() system calls as well as C fopen()/fgetc()/fread() functions and measure how long it takes to finish reading the file.
use gcc -Wall command
open: is a Unix system call that opens a given file.
read: is a Unix system call that reads a file into a given buffer.
close: is a Unix system call that closes a given file.
fopen: is a C standard I/O function that opens a given file.
fgetc: is a C standard I/O function that reads one byte from a file.
fread: is a C standard I/O function that reads a file into a given data structure.
fclose: is a C standard I/O function that closes a give file.
starting code
struct timeval start, end; // maintain starting and finishing wall time.
void startTimer( ) { // memorize the starting time
gettimeofday( &start, NULL );
}
void stopTimer( char *str ) { // checking the finishing time and computes the elapsed time
gettimeofday( &end, NULL );
printf("%s's elapsed timet= %ld",str, ( end.tv_sec - start.tv_sec ) * 1000000 + (end.tv_usec - start.tv_usec ));
}
int main( int argc, char *argv[] ) {
int typeofcalls;
// validate arguments
// // implementation
// Parsing the arguments passed to your C program
// Including the number of bytes to read per read( ) or fread( ), and
// the type of i/o calls used
// implementation
//
if (typeofcalls == 1) {
// Use unix I/O system calls to
// implementation
} else if (typeofcalls == 0) {
// Use standard I/O
// implementation
}
return 0;
}
Numerical Methods With Chemical Engineering Applications
ISBN: 9781107135116
1st Edition
Authors: Kevin D. Dorfman, Prodromos Daoutidis