//------------------------------------------------------------------- // mk1440kb.cpp // // This program will create a file with 1440 killobytes in the // current working directory (for use with Lab #11 questions). // // programmer: ALLAN CRUSE // written on: 05 DEC 2004 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for read(), write(), close() #include // for strncpy() int main( int argc, char **argv ) { char filename[] = "file1440"; // create the named file int fd = creat( filename, 0666 ); if ( fd < 0 ) { perror( filename ); exit( 1 ); } // write data to the new file char data[ 1024 ] = ""; memset( data, 0x20, 1024 ); strncpy( data, filename, sizeof( filename ) ); for (int i = 0; i < 1440; i++) { int nbytes = write( fd, data, sizeof( data ) ); if ( nbytes < sizeof( data ) ) { perror( "write" ); break; } } close( fd ); printf( "created \'%s\' \n\n", filename ); }