Preguntar usually takes three arguments: the subject (who asks the question?), the direct object (what is the question?) and this optional indirect object (who is the question directed to?).
In a quoted dialogue in a book, in general, the sentence between quotes (the direct object, i.e. what is being said) comes first, then the verb, then the person who asks (the subject). In this last part of the sentence you can have the indirect object. But if the participants have already been mentioned, the pronoun is optional, because you can get from context who is being asked.
Sometimes, though, there's no specific person being asked; the verb just means "to ask" in the sense of stating a question and waiting for someone to reply. This works like that with "to ask" in English, anyway.
ADDENDA: The following are examples of preguntar with different arrangements of arguments.
With 3 arguments:
- María le preguntó a Pedro si quería tomar café. = "María asked Pedro if he wanted to have coffee." Here the subject is explicit (María), then comes the indirect object le and a Pedro, and then the direct object, which is the question si quería tomar café (it's not actually a question, but it's the indirect rendering of a yes-no question). The pronoun le is optional, because the indirect object is made explicit: a Pedro, but most people would use the pronoun rather than dropping it.
- "¿Quieres tomar café?", le preguntó María a Pedro. = "'Do you want to have coffee?', María asked Pedro." This is the same as above, only the question is not reported but quoted directly. Again the pronoun le is optional.
- "¿Quieres tomar café", le preguntó María. = "'Do you want to have coffee?', María asked him." Here the indirect object is implicit; the pronoun le points to someone (some definite person) who must have been named before. I've translated it "him" but it could be "her", since le doesn't show gender, only number (singular).
With 2 arguments:
- María preguntó si alguien quería tomar café. = "María asked if anyone wanted to have coffee." Here there's no indirect object pronoun, and there can't be, because the question is intended to be non-specific (alguien = "anyone"). So María doesn't ask someone; she just asks, in general. María is the subject and si alguien quería… (the question) is the direct object.
- "¿Alguien quiere tomar café?", preguntó María. = "'Does anyone want to have coffee?', asked María." As above, with a direct quote. Note the word order change, which you find also in English. This is not a hard-and-fast rule but it does tend to happen.
- With 1 argument:
- María preguntó pero no obtuvo respuesta. = "María asked but got no answer." This is the verb with only a subject. Syntactically there's no direct or indirect object. But in fact this sentence does refer to something that must have been alluded to before in the conversation.
- María preguntó por el café. = "María asked about the coffee." Again, only the subject appears, but the topic of the question is introduced by a complement headed by the preposition por "about" (it could also be sobre). There's no specific question, just a topic (what María wants with the coffee is unknown).