C语言中的打印字符串问题
我有这个结构C语言中的打印字符串问题,c,string,struct,printf,C,String,Struct,Printf,我有这个结构 typedef struct tree_node_s{ char word[20]; struct tree_node_s *leftp,*rightp; }fyllo 我想在一个文件中打印这个单词,并使用fprintf进行即时通讯 问题出在眼前 void print_inorder(fyllo *riza,FILE *outp){ if (riza==NULL) return ; print_inorder(riza->l
typedef struct tree_node_s{
char word[20];
struct tree_node_s *leftp,*rightp;
}fyllo
我想在一个文件中打印这个单词,并使用fprintf进行即时通讯
问题出在眼前
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);
}
我正在编译,我遇到了这个问题
tree.c: In function ‘print_inorder’:
tree.c:35: warning: passing argument 1 of ‘fprintf’ from incompatible pointer type
这里有什么问题 您打错了
fprintf
。此函数的声明是
int fprintf(FILE *restrict stream, const char *restrict format, ...);
因此,您应该将文件指针作为第一个参数(您是否注意到您从未在函数中实际使用过outp
)。该行应写为
fprintf(outp, "%s", riza->word);
fprintf
的第一个参数应该是要打印到的文件*
:
fprintf(outp, "%s", riza->word);
试着改变
fprintf("%s",riza->word);
到
或者,正如他们所说的RTFM。。。尤其是当您以前从未使用过该函数时:)不要忽略编译器警告。包括适当的头文件。
fprintf(outp, "%s", riza->word);