#include <stdio.h>
#include <fcntl.h>
#include <errno.h>

int main(int argc, char *argv[]) {
	 int i,n,f;
	 char buffer[256];

	 if (argc!=3) {
		  printf("Uso: %s <intero positivo> <nomefile>\n",argv[0]);
		  exit(15);
	 }

	 sscanf(argv[1],"%d",&n);

	 f=open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 00644);

	 if (f==-1) {
		  printf("Non riesco ad aprire il file!\n");
		  exit(15);
	 }

	 for (i=1; i<=10; i++) {
		  sprintf(buffer,"%2d x %2d = %3d\n",n,i,i*n);
		  if (write(f,buffer,strlen(buffer))==-1)
				printf("Non riesco a scrivere! Errore: %d\n",errno);
		  }

	 close(f);
}

-- AntonioValletta - 12 Nov 2001


This topic: Sistemioperativi1 > Tabelline
Topic revision: r3 - 2001-11-26 - AntonioValletta
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback