Dch*_*ris 0 c string printf struct
我有这个结构
typedef struct tree_node_s{
char word[20];
struct tree_node_s *leftp,*rightp;
}fyllo
Run Code Online (Sandbox Code Playgroud)
我想在文件中打印这个单词,并且使用fprintf,问题在于PROBLINE
void print_inorder(fyllo *riza,FILE *outp){
if (riza==NULL) return ;
print_inorder(riza->leftp,outp);
fprintf("%s",riza->word); //PROBLINE
print_inorder(riza->rightp,outp);
}
Run Code Online (Sandbox Code Playgroud)
即时编译,我遇到了这个问题
tree.c: In function ‘print_inorder’:
tree.c:35: warning: passing argument 1 of ‘fprintf’ from incompatible pointer type
Run Code Online (Sandbox Code Playgroud)
这是问题所在;
你fprintf错了.这个函数的声明是
int fprintf(FILE *restrict stream, const char *restrict format, ...);
Run Code Online (Sandbox Code Playgroud)
因此,您应该将FILE指针作为第一个参数(您是否注意到您从未outp在函数中实际使用过?).该行应写为
fprintf(outp, "%s", riza->word);
Run Code Online (Sandbox Code Playgroud)