本文介绍了错误C2664:'fscanf':无法将参数1从'char [3]'转换为'struct _iobuf *'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <process.h>

struct Planet
{
   char name[20];
   double dist;
};

struct TreeNodeHdr
{
   struct Planet *planetptr;
   struct TreeNodeHdr *left, *right;
};
struct TreeNodeHdr *head = NULL;
FILE *input, *output;//create two objects of file;
int search(struct TreeNodeHdr *temp, struct Planet *p)
{
  if(temp==NULL)
   {
      return 0;
   }
  else
   {
      if(temp->planetptr->dist == p->dist)
    return 1;
      search(temp->left,p);
      search(temp->right,p);
   }
}

struct TreeNodeHdr* createTreeNode(struct TreeNodeHdr *t,struct Planet *p)
{
    struct TreeNodeHdr *newnode,*temp;
    if( search(t,p) ==1 )
     {
      printf("\n\n\t Already Exists !!");
      getch();
      return t;
     }
    else
     {
    newnode = (struct TreeNodeHdr *) malloc (sizeof(struct TreeNodeHdr));
    newnode->left = newnode->right = NULL;
    newnode->planetptr = p;
    if(t==NULL)
     {
        t = newnode;
     }
    else
     {
        temp = t;
        while(temp)
         {
           if(p->dist < temp->planetptr->dist)
         {
            if(temp->left == NULL)
             {
               temp->left = newnode;
               break;
             }
            else
               temp = temp->left;
         }
           else
         {
            if(temp->right == NULL)
             {
               temp->right = newnode;
               break;
             }
            else
               temp = temp->right;
         }//end left else
         }//end while
     }//end null else
     }//end search else
     return t;
}

void in_order(struct TreeNodeHdr *temp)
{
  if(temp==NULL)
   {
      return;
   }
  else
   {
      in_order(temp->left);
      printf("\n %s \t -> \t %lf", temp->planetptr->name, temp->planetptr->dist);
      in_order(temp->right);
   }
}
void reverse(struct TreeNodeHdr *temp)
{
  if(temp==NULL)
   {
      return;
   }
  else
   {
      reverse(temp->right);
      printf("\n %s \t -> \t %lf", temp->planetptr->name, temp->planetptr->dist);
      reverse(temp->left);
  }
}
int main()
{
   struct Planet *p;
   int choice;
   printf("\n Read  Details of 9 planets");
   input = fopen("PlanetData.dat", "r");//open PlanetData.dat file and read planet data for each planet from it;
   if (input == NULL)
   {
       printf("error: input\n");
       exit(-1);
   }

   do
    {
 //     clrscr();
      printf("\n1. Enter Planet");
      printf("\n2. Show Planets");
      printf("\n3. Show Planets In Reverse");
      printf("\n4. Exit");
      printf("\n\n Enter Your Choice: ");
      scanf("%d",&choice);
      switch(choice)
       {
     case 1:
         p = (struct Planet *) malloc(sizeof(struct Planet));
         printf("\n Enter Name of Planet: ");
         fscanf("%s",p->name);
         printf("\n Enter Distance From Sun: ");
         fscanf("%lf",&p->dist);
         head = createTreeNode(head, p);
         break;
     case 2:
         printf("\n\n The Planet List Is: \n");
         in_order(head);
         getch();
         break;
     case 3:
         printf("\n\n The Planet List Is: \n");
         reverse(head);
         getch();
         break;
     case 4: exit(0);
       }
    }while(1);
    fclose(input);
   return 0;
}

推荐答案


这篇关于错误C2664:'fscanf':无法将参数1从'char [3]'转换为'struct _iobuf *'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 12:47