Thread: Help with returning an array

  1. #16
    Registered User
    Join Date
    Mar 2010
    Posts
    17
    Hello again

    I was trying for a while understading but i can't figured it out.

    When i get this code
    Code:
    char op[]="cr test";
    //teste(op);
    char **comando=teste(op);
    printf("COMANDO1: %s\n",comando[0]);
    it work nice comando[0] is cr and comando[1] is test.
    but i i put
    Code:
    char op[]="p 1 3";
    //teste(op);
    char **comando=teste(op);
    char *com=comando[0]; /*it will be "p"
    int *x=comando[1];/*should be 1
    int *y=comando[2];/*should be 3
    printf("comando:%s %d %d\n",com,x,y);
    don't work as i expect.
    it does like this
    Letrorium>p 1 3
    comando -1081791238 -1081791236

    why?

  2. #17
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    That code will not produce the output you describe. In fact, the code won't even compile because of type mismatches.

    The statement "char *com = comando[0]" is invalid as comando[0] is a char (with value 'p') and com is a pointer to char.

    The statement "int *x = comando[1]" is invalid, as comando[1] is a char, and x is a pointer to int.

    Incidentally, comando[1] is the value of the second character in op. That is a space character which, with on many systems, has the value 32.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Parsing and returning array pointers?
    By thealmightyone in forum C Programming
    Replies: 26
    Last Post: 03-26-2009, 03:38 PM
  2. Returning an Array
    By mmarab in forum C Programming
    Replies: 10
    Last Post: 07-19-2007, 07:05 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Replies: 6
    Last Post: 10-21-2003, 09:57 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM