I don't understand K&R example
Hi, all. I'm writing because there's something I don't understand in K&R's book. In Section 1.9 (character arrays), an example code is given in which the main function calls a function named getline. When getline is called for the first time, two arguments are (supposedly) passed to it, a character array named line and an integer named maxline.
Right at this point I get confused. Up to this point in the code, the line array has only been declared but it has not been assigned any value. So, if line has not been assigned any value before calling getline, how does any character array get passed to this last function?
In Section 1.7 (functions), a function named power is called by main. But this time, two previously defined arguments are passed to power. This example I can understand, but the inner working of the example in Section 1.9 is uncomprehensible for me at my current level in C programming.
So, if anyone knows how to give a clear explanation about this subject, I'd love to hear it.
Thanks in advance to those who take the time to read this post.
Roberto.
I'm talking about the first chapter
Hi. I'm talking about something that's in chapter 1, section 9. I have a spanish copy of the book. In my copy, the code I'm talking about is in page 31.
Hope this helps.
I didn't quite understand the code you wrote.
Thanks,
Roberto.
I´m beginning to understand
Hi. First of all, I´d like to thank all of you who replied to my message for your time and effort.
That said, I go back to business. I assume (from what kermit posted) that all that the function main must pass to the function getline is the address of the first element of the array line and its size in order for the latter function to work properly. There is no need for the array to have a value before making the call to getline . Is that the right reasoning? If what I think is right, then it is optional (dependent on what you want the program to perform) to pass a value of a character array to a function when it is called. Please correct me if I´m wrong.
As I said in my first post to this thread, this is the very fact that led me to confusion.
Since I´m new to the world of C programming, this behavior of the language took me by surprise.
Thanks again to you all,
Roberto.