This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Newbie Hello


On Sun, 2004-08-15 at 00:30, Larry Brown wrote:
> I hope I'm in the right place... I am a fairly accomplished php
> developer and have written quite a bit of code with it.  However, all of
> my coding experience has been with scripting languages and I have never
> had to deal with memory allocation and rarely ever dealt with pointers
> or casting etc.
> 
> For instance...
> 
> with scripting I can simply access arguments by referencing the string
> at argv[1] or ARGV[1] etc.  It looks like I should be able to do this
> with c but I have to reference *argv[x] and *argv[x] only holds the
> first character.  The following is a snippet...
> 
> int main(int argc, *argv[])
> {
> 	int secondVar=*argv[2];
> }
> 
> if the second argument is say ... 10, I only get the 1.  There is some
> logic that I must follow that I can't see.  I've tried looking at
> *argv[2][0] to see if it was one and *argv[2][1] was zero but is
> aparently not the case.
> 
> I have looked at several howto/instruction documents and none seem to
> yeild much.  
> 
> TIA
> 
> Again, I hope I'm in the right place...
> 
> Larry


Try this:

main.c:
-------

      1 #include <stdio.h>
      2 #include <stdlib.h>
      3
      4 int main( int argc, char * argv[] )
      5 {
      6
      7 char * stringVar = argv[1];
      8 printf( "stringVar = %s\n", stringVar );
      9 int numberVar = atoi( stringVar );
     10 printf( "numberVar = %d\n", numberVar );
     11
     12
     13 return 0;
     14 }


> gcc -g -Wall -o args main.c
> ./args 10
stringVar = 10
numberVar = 10
>


-- 
Arno Wilhelm <arno.wilhelm@profile.co.at>
proFILE Computersysteme GmbH


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]