Difference between revisions of "ProvaPratica 2009.02.12"
Jump to navigation
Jump to search
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...") |
Stefano 92 (talk | contribs) |
||
Line 17: | Line 17: | ||
int main(int argc,char* argv[]) | int main(int argc,char* argv[]) | ||
{ | { | ||
− | char* tmp_i,*tmp_x | + | char* tmp_i,*tmp_x; |
int x=(argc-1),i=2; | int x=(argc-1),i=2; | ||
if (argc<2) | if (argc<2) |
Revision as of 15:01, 28 April 2014
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;
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