www.digitalmars.com         C & C++   DMDScript  

D - Back from the land of pain

reply "Andrew Edwards" <crxace13 comcast.net> writes:
Hi everyone! How's it been?
Walter my man...I see you're still hard at work!
Matthew...I see the Journal is progressing a little slower than we'd
like...patience my brother, it will all come together when the time is
right.  Just be ready to capitalize when that time does arrive.

Pavel, Anderson, Carlos, Sean and the rest of the gang (too many to name),
thanks for keeping the ideas flowing and preventing Walter from going into
shellshock.

I've just returned from training and am happy to see you guys still
plugging at it.

I'm wandering if someone could help me out a little?
The following is an example that Walter provides with the compiler.  Fairly
simple no doubt, however my "pre-processor" (translation: feeble brain) is
not making all the right connections between code and output.

int main(char[][] args)
{
    printf("hello world\n");
    printf("args.length = %d\n", args.length);
    for (int i = 0; i < args.length; i++)
 printf("args[%d] = '%s'\n", i, (char *)args[i]);
    return 0;
}

I understand what it does but not how or why it does it!
I'm completely lost on the "int main (char[][] args)" thing since cannot
come up with an equivalent C++ example.  From what I've learned (first C++
class during the summer) you start your programs with int main() or int
main(void).  I've got a long way to go, but this would help out allot.

Thanks.
Andrew
D Rules!!!
Aug 21 2002
parent reply "Carlos" <carlos8294 msn.com> writes:
"Andrew Edwards" <crxace13 comcast.net> escribió en el mensaje
news:ak1dia$1qke$1 digitaldaemon.com...
 Pavel, Anderson, Carlos, Sean and the rest of the gang (too many to name),
 thanks for keeping the ideas flowing and preventing Walter from going into
 shellshock.

many other have done.
 I'm wandering if someone could help me out a little?
 The following is an example that Walter provides with the compiler.

 simple no doubt, however my "pre-processor" (translation: feeble brain) is
 not making all the right connections between code and output.

 int main(char[][] args)
 {
     printf("hello world\n");
     printf("args.length = %d\n", args.length);
     for (int i = 0; i < args.length; i++)
  printf("args[%d] = '%s'\n", i, (char *)args[i]);
     return 0;
 }

 I understand what it does but not how or why it does it!
 I'm completely lost on the "int main (char[][] args)" thing since cannot
 come up with an equivalent C++ example.  From what I've learned (first C++
 class during the summer) you start your programs with int main() or int
 main(void).  I've got a long way to go, but this would help out allot.

This C/C++ program does the same: #include <stdio.h> int main(int argc,char *argv[]) { int i; for (i=0;i<argc;i++) printf("%s\n",argv[i]); return 0; } In C (and C++) the main function takes two parameters: an integer representing the number of arguments passed to the program, and array of char* which contains those arguments. You can omit them, and that's probably what you've learned. In D, the main function only takes one parameter: an array of strings which contains the arguments passed to the program. Since arrays have the length property, there's no need to specify how many they're. I hope that helps.
 Thanks.
 Andrew
 D Rules!!!

Aug 21 2002
next sibling parent "Andrew Edwards" <crxace13 comcast.net> writes:
Thanks Carlos,
That does the trick!

"Carlos" <carlos8294 msn.com> wrote in message
news:ak1fvb$2jcj$1 digitaldaemon.com...
|
| "Andrew Edwards" <crxace13 comcast.net> escribió en el mensaje
| news:ak1dia$1qke$1 digitaldaemon.com...
| >
| > Pavel, Anderson, Carlos, Sean and the rest of the gang (too many to
name),
| > thanks for keeping the ideas flowing and preventing Walter from going
into
| > shellshock.
| >
| If that was to me, thanks! I'm flattered. I've done nothing considering
what
| many other have done.
|
| >
| > I'm wandering if someone could help me out a little?
| > The following is an example that Walter provides with the compiler.
| Fairly
| > simple no doubt, however my "pre-processor" (translation: feeble brain)
is
| > not making all the right connections between code and output.
| >
| > int main(char[][] args)
| > {
| >     printf("hello world\n");
| >     printf("args.length = %d\n", args.length);
| >     for (int i = 0; i < args.length; i++)
| >  printf("args[%d] = '%s'\n", i, (char *)args[i]);
| >     return 0;
| > }
| >
| > I understand what it does but not how or why it does it!
| > I'm completely lost on the "int main (char[][] args)" thing since
cannot
| > come up with an equivalent C++ example.  From what I've learned (first
C++
| > class during the summer) you start your programs with int main() or int
| > main(void).  I've got a long way to go, but this would help out allot.
| >
|
| This C/C++ program does the same:
|
| #include <stdio.h>
| int main(int argc,char *argv[])
| {
|     int i;
|     for (i=0;i<argc;i++)
|         printf("%s\n",argv[i]);
|     return 0;
| }
|
| In C (and C++) the main function takes two parameters: an integer
| representing the number of arguments passed to the program, and array of
| char* which contains those arguments. You can omit them, and that's
probably
| what you've learned.
| In D, the main function only takes one parameter: an array of strings
which
| contains the arguments passed to the program. Since arrays have the
length
| property, there's no need to specify how many they're.
| I hope that helps.
|
| > Thanks.
| > Andrew
| > D Rules!!!
| >
|
|
Aug 22 2002
prev sibling parent "Sandor Hojtsy" <hojtsy index.hu> writes:
"Carlos" <carlos8294 msn.com> wrote in message
news:ak1fvb$2jcj$1 digitaldaemon.com...
 int main(char[][] args)
 {
     printf("hello world\n");
     printf("args.length = %d\n", args.length);
     for (int i = 0; i < args.length; i++)
  printf("args[%d] = '%s'\n", i, (char *)args[i]);
     return 0;
 }

 I understand what it does but not how or why it does it!
 I'm completely lost on the "int main (char[][] args)" thing since cannot
 come up with an equivalent C++ example.  From what I've learned (first


 class during the summer) you start your programs with int main() or int
 main(void).  I've got a long way to go, but this would help out allot.

This C/C++ program does the same: #include <stdio.h> int main(int argc,char *argv[]) { int i; for (i=0;i<argc;i++) printf("%s\n",argv[i]); return 0; }

Hmm, in an ideal non-existent C++, the function header could be : int main(vector<string> args)
Aug 26 2002