here is a sample assigment i did from the k&r book which uses the commandline arguments . i think some gui libraries uses commandline parameters internally to keep track of some things but i am not that far into my studies of c that i can say if that is true or not.
Code:
#include <stdio.h>
#define IN 1
#define OUT 0
int main(int argc,char *argv[]){
int c;
int nl,nw,nc,state;
nl=nw=nc=state=0;
FILE *fp;
if(argc != 2)
{
fprintf(stderr," %s: too few arguments for format\n",argv[0]);
return 1;
}
if((fp=fopen(argv[1],"r")) != NULL)
{
/* we opened a file to read it and count it*/
while((c=getc(fp))!= EOF)
{
nc++;
if(c=='\n')
nl++;
if(c==' '||c=='\n'||c=='\t')
state=OUT;
else if(state == OUT)
{
state = IN;
++nw;
}
}
fprintf(stdout,"%d %d %d\n",nl,nw,nc);
}
else
{
fprintf(stderr,"error in opening file %s\n",argv[1]);
return 1;
}
return 0;
}
i am not sure if you can read it and i waiting for a eye operation so i read and write really bad at the moment but i hope it was helpful -(and i posted it in t he right context if not then ignore post please. )