Thread: argv weirdness

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2005
    Location
    german border
    Posts
    72

    argv weirdness[SOLVED]

    Hi,

    I'm experimenting with argv to learn more about how it works for a program I'm writing. I'm working with the code below:

    Code:
    #include<stdio.h>
    
    int main( int argc, char **argv)
    {
        char *array = argv[1];
        int i;
        printf( "%d\n", sizeof(array));
        for( i = 0; i < sizeof(array); i++ )
        {
            printf( "%c\n", array[i] );
        }
        return(0);
    }
    The thing that has me is the following behaviour:

    [calef13@bluenode c]$ ./test1 127.0.0.1 1-20
    4
    1
    2
    7
    .
    [calef13@bluenode c]$
    Can anybody here explain why it's stopping at the first 0? I can't for the life of me fathom it. But I suspect I'm doing something undefined. The code above works just fine for a second parameter "1-200". Also if there is a better way to get a string out of argv so it can be compared character by character, let me know.
    Last edited by Calef13; 12-16-2008 at 02:36 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. argv
    By taurus in forum C Programming
    Replies: 15
    Last Post: 10-14-2007, 08:57 AM
  2. Using argc and argv data
    By Rad_Turnip in forum C Programming
    Replies: 4
    Last Post: 03-31-2006, 06:09 AM
  3. how do i? re: argc - argv
    By luigi40 in forum C Programming
    Replies: 2
    Last Post: 06-11-2004, 10:17 AM
  4. Argv And Argc
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 12-11-2001, 03:43 PM
  5. more argv and argc
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 09-08-2001, 11:04 PM