ProvaPratica 2009.02.12

From Sistemi Operativi
Revision as of 15:00, 28 April 2014 by Stefano 92 (talk | contribs) (Created page with "<h1>http://www.cs.unibo.it/~renzo/so/compiti/2009-02-12.pdf</h1> == Esercizio 1 == <syntaxhighlight lang="C"> #include <stdio.h> #include <stdlib.h> #include <string.h> #in...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

http://www.cs.unibo.it/~renzo/so/compiti/2009-02-12.pdf


Esercizio 1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

void usage()
{
	printf("usage: ./invarg.out EXEC_NAME [ARG1] [ARG2] ... [ARGN]\n");
}

int main(int argc,char* argv[])
{
   char* tmp_i,*tmp_x,*bin="/bin/";
   int x=(argc-1),i=2;
   if (argc<2)
   {
   		usage();
   		return(1);
   }
   while(i<x)
   {
       tmp_i=argv[i];
       tmp_x=argv[x];
       argv[i]=tmp_x;
       argv[x]=tmp_i;
       i++;
       x--;
   }
	for(i=0;i<argc-1;i++)
		argv[i]=argv[i+1];
	
	argv[argc-1]=NULL;
	argc--;
	execvp(argv[0],argv);
	return 0;
}

stefano92