Skip to content

Instantly share code, notes, and snippets.

@satishgoda
Created December 30, 2013 12:41
Show Gist options
  • Save satishgoda/8181686 to your computer and use it in GitHub Desktop.
Save satishgoda/8181686 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int argcorig = 0;
char **argvorig = NULL;
char **envorig = NULL;
char **arg = NULL;
char **env = NULL;
typedef void (*exitcallback) ();
void numargs()
{
printf("The number of command-line arguments are %lu %d\n", arg - argvorig, ((arg - argvorig == argcorig)));
}
void numenvirons()
{
printf("The number of environment variables are %lu \n", env - envorig);
}
int main(int argc, char *argv[], char *environ[])
{
exitcallback numargsatexit = &numargs;
exitcallback numenvironsatexit = &numenvirons;
atexit(numenvironsatexit);
atexit(numargsatexit);
argcorig = argc;
arg = argv;
argvorig = argv;
while (*arg != NULL) { ++arg; }
env = environ;
envorig = environ;
while (*env != NULL) { ++env; }
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment