//------------------------------------------------------------------- // mkfiles.cpp // // This program will create 200 differently named files 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[] = "filexxxx"; for (int i = 1; i <= 200; i++) { // prepare the next filename sprintf( filename+4, "%04u", i ); // create the named file int fd = creat( filename, 0666 ); if ( fd < 0 ) { perror( filename ); exit( 1 ); } // write data to the new file char data[ 16 ] = ""; strncpy( data, filename, sizeof( filename ) ); int nbytes = write( fd, data, sizeof( data ) ); if ( nbytes < sizeof( data ) ) { perror( "write" ); break; } close( fd ); printf( "created \'%s\' \n", filename ); } printf( "\n" ); }