¿Estructura que apunta a una función que apunta a un puntero de archivo?
Frecuentes
Visto 132 veces
1
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.
3 Respuestas
5
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
1
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
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c struct or haz tu propia pregunta.
node_t *
es igual quenode_t*
. Probably the space character confused you. - MaheshYour professor is using "interface" correctly. - Adam Burry