Yes, it is most definitely possible, and that's exactly what command line arguments are passed to your program as. If you write a C program that takes command line arguments, your main function will look like this:
or it could beCode:int main(int argc, char * argv[]){
Which both accomplish the same thing. So if you wanted an array of pointers to character pointers you could have:Code:int main(int argc, char ** argv){
I could have put "five" where I have NULL, but I put NULL for a reason. That's how you know when there are no more lines left.Code:char * lines[5] = { "one", "two", "three", "four", NULL };
Since NULL marks the end, you can traverse the array until you find NULL as above. With our main example above the variable argc is the number of elements in the argv array. Typically you're going to know how many elements are in the array and you can use that to traverse in a for loop, but if you don't, the last element should be NULL and you can use that knowledge to traverse until the end. I hope this helped.Code:char ** ptr = lines; while(*ptr != NULL){ printf("%s\n", *ptr); ptr++; }




Reply With Quote