asma sabir wrote:
I'm doing OS course in Linux where I m not understanding the command line. is
it like DOS cmd line? And I am too confused in cammand_line_arguments like argc
and pointer argv. I want to know about each and every thing about these,
because of this i could not understand the below code and similar of it.There
are 2 files below.Can anybody explain this code specially the main() function
with its arguments?Pleaseeee........
My reply:
> the command line. is it like DOS cmd line?
Are you referring to bash? It is much better than Windows' cmd. DOS used
command.com .
> There are 2 files below.Can anybody explain this code specially the main()
> function with its arguments?
argv points to an array of pointers to strings. Try to printf ("%p %p\n",
argv, argv[0]);
I decided to modify the code to be easier to understand. If you do not
understand, ask what does a specific line.
# include <errno.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
int main(int argc,char *argv[])
{
FILE *in;
int count=0;
int ch;
if(argc<2)
{
fprintf(stderr, "I %s require a filename.\n", argv[0]);
exit(1);
}
if((in=fopen(argv[1],"r"))== NULL)
{
fprintf (stderr, "%s : %s\n", argv[1], strerror(errno));
exit(2);
}
while ((ch=getc(in))!=EOF)
if(ch=='\n')
count++;
fclose(in);
printf("%d\n",count);
return 0;
}
____________________________________________________________________________________
Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel
and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/c-prog/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/c-prog/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/