Can anyone explain me what argc and argv does in this code and why those variables are parameters in the main function? We had in lectures example that showed those both variables so I'm using them without knowing what they do.
main (argc, argv)
char *argv[];
{
int fd;
extern int errno;
if(argc < 2){
fprintf(stderr, "No file\n");
exit(1);
}
if((fd = creat(argv[1], 0777)) < 0){
fprintf(stderr, "Cannot creat file %s\n", argv[1]);
exit(1);
}
switch (fork()) {
case -1:
fprintf(stderr, "Fork error\n");
exit(1);
case 0:
close(1);
dup(fd);
close(fd);
execl("/bin/pwd", "pwd", NULL);
perror("Exec");
break;
default:
close(fd);
}
exit(0);
}