Difference between revisions of "Esempi del 02 dicembre 2014"
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
| Line 33: | Line 33: | ||
    char* str = "ciao";  |     char* str = "ciao";  | ||
| − | |||
| − | |||
    lseek(file, MILIONE, SEEK_SET);  |     lseek(file, MILIONE, SEEK_SET);  | ||
Revision as of 17:17, 2 December 2014
scrivere un programma C che faccia lseek a 1miliardo (SEEK_SET) e scriva "ciao".
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
int main( int argc, char* argv[]){
	int f;
	f = open( argv[1] , O_WRONLY | O_CREAT );
	lseek( f , 1000000000 , SEEK_SET ) ;
	write( f , "ciao" , 4 ) ;
	return 0 ;
}
Non sono effettivamente riuscito ad aprire il file creato, ma ha la dimensione di 1 Gigabyte.
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#define MILIONE 1000000
int main(int argc, char* argv[])
{
   int file;
   file = open("./test.txt", O_WRONLY | O_CREAT | O_TRUNC);
   char* str = "ciao";
   lseek(file, MILIONE, SEEK_SET);
   write(file, str, 5);
   exit(0);
}