upper.c
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
char ch;
while((ch=getchar()) != EOF)
putchar(toupper(ch));
exit(0);
}
usupper.c
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
int main(int argc,char *argv[])
{
char* filename;
if(argc != 2)
{
fprintf(stderr,"usage:useupper file\n");
exit(1);
}
printf("%s\n",argv[0]);
printf("%s\n",argv[1]);
filename = argv[1];
if(!freopen(filename,"r",stdin))
{
fprintf(stderr,"couldn't open the file %s",filename);
exit(2);
}
execl("./upper","upper",0);
perror("could not exec ./a.out");
exit(3);
}