URGENT

0 views
Skip to first unread message

Rahul Gupta

unread,
Nov 18, 2009, 12:07:03 PM11/18/09
to csl-101-gr...@googlegroups.com
Could you guys ask Aksay Balsaraf to talk to me .... It's urgent !!!


Rahul

2009/11/18 Rahul Gupta <rah...@gmail.com>
The ouput as shown is
"
$ cc args.c -o args.out
$ ./args.out 2  join leave 6
6
leave
join
2
./args.out
"

* argc =5
* What are the various values of the elements present is argv ?

argv[0]= ./args.out
argv[1] = 2
argv[2] = join
argv[3] = leave
argv[4] = 6


So the program will print from argv[4] till argv[0]

I hope I am making sense.


Rahul




2009/11/18 tarang gupta <tara...@gmail.com>
but sir the main problem is the output
will you please show how the programme would run on putting the set of
values taken in the slide

On Wed, Nov 18, 2009 at 8:48 PM, Rahul Gupta <rah...@gmail.com> wrote:
>
> The code given is
>
> "
>
> main(int argc,char *argv[])
> {
>   while(argc>0)      /* print out all arguments in reverse order*/
>     {
>       printf("%s\n",argv[argc-1]);
>       argc--;
>     }
> }
>
> "
>
> 1) argc stores the number of elements which would be there in the array argv
>
> 2) So just considering argv as an array with number of elements (= argc),
> how will you print the elements of that array in reverse order ??
>
> Array argv has elements from i=0 till i=argc-1
> You would start from the end of the array ie.from argv[argc-1] ..print the
> value stored at that location and decrement i.
>
> The above program can be rewritten as
>
> for (i=argc-1;i>0;i--)
> printf("%s",argv[i];
>
> Compare both the programs and understand how both of them are essentially
> the same only.
>
>
>
> 2009/11/18 tarang gupta <tara...@gmail.com>
>>
>> sir the programme given for command line arguments on the lecture
>> notes at saroj mam's webpage for file handling given on the last slide
>> is not understandable
>> pls mail an explanation for it
>
>


Reply all
Reply to author
Forward
0 new messages