代码之家  ›  专栏  ›  技术社区  ›  Dchris

C语言中的打印字符串问题

  •  0
  • Dchris  · 技术社区  · 14 年前

    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
    

    这里有什么问题;

    3 回复  |  直到 14 年前
        1
  •  6
  •   kennytm    14 年前

    你在打电话 fprintf

     int fprintf(FILE *restrict stream, const char *restrict format, ...);
    

    因此,您应该将文件指针作为第一个参数(是否注意到您从未实际使用过 outp 在函数中?)。该行应写为

    fprintf(outp, "%s", riza->word);
    
        2
  •  3
  •   John Ledbetter    14 年前

    第一个论点 fprintf 应该是 FILE*

    fprintf(outp, "%s", riza->word);
    
        3
  •  2
  •   mcabral    14 年前

    尝试改变

    fprintf("%s",riza->word); 
    

    fprintf(outp, "%s", riza->word);