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:
The thing that has me is the following behaviour: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);
}
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.Quote:
[calef13@bluenode c]$ ./test1 127.0.0.1 1-20
4
1
2
7
.
[calef13@bluenode c]$