¿Estructura que apunta a una función que apunta a un puntero de archivo?

I have been tasked with writing a program that will be a unbalanced BST of linked lists, basically a linked list of linked lists. My struct for the nodes is as follows:

typedef struct node
{
    int node_num;
    struct node *right, *left;
} node_t;

Now according to my professor I must use this "interface" (his words not mine).

node_t *buildTree(FILE *); 

Can someone explain the above "interface?" I gather that,

buildTree(File *);

is my function declaration and

node_t

is my typedef struct. But I am not understanding seeing it all together. I have not run across this type of declaration before.

Agradezco la ayuda.

preguntado el 09 de septiembre de 13 a las 21:09

node_t * es igual que node_t*. Probably the space character confused you. -

Your professor is using "interface" correctly. -

3 Respuestas

this is a function, that is given an open file (someone else opened the file and gave you the FILE*).

You are to read some data out of that file, and turn it into a bunch of nodes for your BST.

Finally, you are to return a pointer to the top / head node (a node_t*)

Entonces, comienzas con:

node_t* buildTree(FILE* myFile)
{
    node_t* treeRoot = NULL;

    fread( [??], [??], [??], myFile );   /* Read something from the file */

    [...]

    return treeRoot;
}

Que haces con [...] is how you earn your paycheck. :)

Respondido el 09 de Septiembre de 13 a las 21:09

How would I declare this function in my .h file? - Clint

La función node_t *buildTree(FILE *); will accept a pointer to type FILE and return a pointer to your type node_t

You function will build a binary tree with the help of FILE pointer, that will be used to read data from an actual file from a disk. The pointer FILE can be passed along to other functions or recursively.

The returned pointer node_t will point to the start of the binary tree.

Respondido el 09 de Septiembre de 13 a las 21:09

node_t* buildTree(FILE *);  // Is a function declaration
    |              |
    |              |
    |              +-------a FILE pointer as argument
    |
    +-------return type: A pointer to struct node_t

Basically you need to "build" a tree using input from a presentar

Respondido el 09 de Septiembre de 13 a las 21:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.