大神帮我看一下这个read函数怎么写

#define   m   15

typedef struct vertexnode//顶点表节点
{
    char name[30];
    char information[100];//信息
    Arcnode* head;//弧节点
} Line;
typedef struct  adjlist//邻接表
{
    Line point[m];//点
    int  arcnum;//边数
    int  vexnum;//顶点数
} graph;//图表
case 0:
            {
                 float matrix[m][m];
                  fp=fopen("graph.txt","rt");
                  read(&g,matrix,fp);
                  fclose(fp);
                  getchar();
                  getchar();
                  break;
            }
void  read(graph* g,float (*matrix)[m],FILE *fp)
{
    
     //printf("creat over!\n");
     //test(g,matrix);
}

又是城市车站系统啊,快交作业了吧......

你都没说文件的数据怎么组成的,谁也不知道改怎么读取,怎么分解出数据项构建图啊

read函数怎么写,要先看你是怎么保存的。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define   m   15
#define   n   50
#define   infinity       99999
typedef struct node
{
   float distence;
   int  vexnode;
   struct node *next;
}Arcnode;
typedef struct vertexnode
{
    char name[30];
    char information[100];
    Arcnode* head;
} Line;
typedef struct  adjlist
{
    Line point[m];
    int  arcnum;
    int  vexnum;
} graph;
typedef struct queue
{
     int father;
     int son;
     struct queue *next;    
}queue;
typedef struct  mst_point
{
    int father;
    int son;
    struct mst_point *next;
}mst_point;
//========================================================================
//creat the graph and test it


void   init_matrix(float (*matrix) [m])
{

}

void  init_graph(graph *g)
{
    
}

void  creat_graph(graph* g,float (*matrix)[m],FILE *fp)
{
     
}

void test(graph *g,float (*matrix)[m])
{

    Arcnode *temp;
    

    
    printf("the matrix is as follows:\n");
    printf("%d\n",g->vexnum );

    //sleep(5);
    
    for (int i = 0; i < g->vexnum; ++i)
    {
        for (int j = 0; j < g->vexnum; ++j)
        {
            printf("%6.1f  ", matrix[i][j]);
        }
        printf("\n");
    }
    printf("\n");
    printf("%d\n", g->vexnum);
    for (int i = 0; i < g->vexnum; ++i)
    {

        temp=g->point[i].head->next;
        printf("point connected to '%s':",g->point[i].name);
        while(temp)
        {
            printf(" (%s,distence:%.1f) ", g->point[temp->vexnode].name,temp->distence);
            temp=temp->next;
        }
        printf("\n");
        printf("information:%s", g->point[i].information);
        printf("\n\n\n");
    }

    

}

//============================================================================

//============================================================================
//creat queue and all related function


queue * init_queue()
{


}


int  empty(queue *head)
{

}


void push(queue *head,int i,int j)   // i:father point   j:son point
{


}


void pop(queue *head,int* i,int* j)
{

}


void print_queue(queue *head)
{

}

/*
void test_queue(queue *head)
{
    head=init_queue();
    int order=-2;
    printf("test push:input the order:\n");
    while(order != -1)
    {              
         scanf("%d",&order);
         push(head,order);
    }
    printf("\n");
    printf("test pop :\n");
    while(!empty(head))
    {    
        pop(head,&order);
        printf("%d ",order);
    }
    printf("\n");
    printf("test push:input the order:\n");
    while(order !=-1)
    {
         scanf("%d",&order);
         push(head,order);
    }
    printf("\n");
    printf("test pop :\n");
    while(!empty(head))
    {    
        pop(head,&order);
        printf("%d ",order);
    }
    print_queue(head);
}
*/ 


//==============================================================
//find all way between two points


void  print_rout(graph *g,queue *head,int end)
{

}

int get_next(graph* g,int* father,int* son)
{
 
}


int contin_find(graph*g,int father,int son,int start)
{

   
}
void  allways_bttps(graph *g,queue *head,int start,int end)

   


/*
void test_dfs(graph *g,queue *head,float (*matrix)[m])
{
    int start=-1,end=-1;
    creat_graph(g,matrix);
    test(g,matrix);
    
    while((start!=0) || (end!=0))
    {
       printf("input the start point and end_point:\n");
       scanf("%d%d",&start,&end);
       allways_bttps(g,head,start,end);
    }
    
}
*/

//=================================================================================


//==================================================================================
//find the shortest way between two points

   


   
void dijkstra(graph *g,float (*matrix)[m],int start,int end,int dist[m],int path[m][m+1])
{
 
}

void test_dijs(int *dist,int path[][m+1])
{
 
}

//===============================================================================
//algorithm prim   to get MST tree


mst_point * prim(graph* g,float(*matrix)[m],int start)
{
 
}


void test_mst(mst_point *head)
{
    mst_point* temp;
    temp=head->next;
    printf("the MST tree is:\n");
    while(temp)
    {
        printf("(%d,%d)  ", temp->father,temp->son);
        temp=temp->next;
    }
    printf("\n");

}

//=================================================================================
void  read(graph* g,float (*matrix)[m],FILE *fp)
{


     //printf("creat over!\n");
    // test(g,matrix);
}

void display(graph *g)
{

}

void Select(graph *g)
{

}

//==================================================================================

void display_mst(graph* g,mst_point *head)
{

}


void add(graph *g,float(*matrix)[m],int start,int end,float distence)
{
 
}

void cut(graph *g,float(*matrix)[m],int start,int end)
{


}

void add_point(graph *g,float (*matrix)[m])
{
   
   // test(g,matrix);
}
/*
void del_point(graph *g,float (*matrix)[m])
{
    int choice;
    printf("\n    places intrduction    \n");
    for (int i = 0; i < g->vexnum; ++i)
    {
        printf("%d : %s\n",i,g->point[i].name);
    }
    printf("input the point you want to del:");
    scanf("%d",&choice);
    getchar();
     
}
*/

int main(int argc, char const *argv[])
{
    
    graph g;
    queue *head;
    float matrix[m][m];
    int path[m][m+1];
    int start,end;
    int dist[m];

    mst_point *Head;

    init_matrix(matrix);

    int point;
    int choice;
    FILE *fp;
    float distence;

    
    while(1)
{

    system("clear");

    printf("                       城 市 区 域 查 询 系 统 demo                \n\n ");
    printf("                                   功能页面                            \n");
    printf("      0.地图的基本信息.                                                \n");
    printf("      1.可供查询的地点及其基本信息介绍                                  \n");
    printf("      2.查询任意两点间所有的路径                                       \n");
    printf("      3.查询两点间最短路径                                            \n");
    printf("      4.查询从某点出发的最短连通路径                                  \n");
    printf("      5.路径的扩充                                                  \n");
    printf("      6.路径的撤销                                                  \n");
    printf("      7.新建整张地图                                                 \n");
    printf("      8.add point                                                  \n");
    printf("      9.delete   point                                             \n");
    printf("      10.退出该系统                                                  \n");
    printf("\n\n  根据序号输入你的选择:   ");
    
    scanf("%d",&choice);
    if(choice==10)
        break;
    else
    {
        switch(choice)
        {
            case 0:
            {
                  fp=fopen("graph.txt","rt");
                  read(&g,matrix,fp);
                  fclose(fp);
                  getchar();
                  getchar();
                  break;

           

            }
            case 1:
            { 
                fp=fopen("graph.txt","rt");
                read(&g,matrix,fp);
                fclose(fp);
                display(&g);
                getchar();
                getchar();
                break;


            }
            case 2:
            {
                fp=fopen("graph.txt","rt");
                read(&g,matrix,fp);
                fclose(fp);
                Select(&g);
                printf("input the start point and target point:");
                scanf("%d%d",&start,&end);
                getchar();
                allways_bttps(&g,head,start,end);
                getchar();
                getchar();
                break;
            }
            case 3:
            {
                 fp=fopen("graph.txt","rt");
                 read(&g,matrix,fp);
                 fclose(fp);
                 Select(&g);
                 printf("input the start point and target point:");
                 scanf("%d%d",&start,&end);
                 getchar();
                 dijkstra(&g,matrix,start,end,dist,path);
                 getchar();
                 getchar();
                 break;
            }
            case 4:
            {
                fp=fopen("graph.txt","rt");
                read(&g,matrix,fp);
                fclose(fp);
                Select(&g);
                printf("input the start point:\n");
                scanf("%d",&start);
                getchar();
                Head=prim(&g,matrix,start);
                display_mst(&g,Head);
                getchar();
                getchar();
                break;
  

            }
            case 5:
            {
                 fp=fopen("graph.txt","rt");
                 read(&g,matrix,fp);
                 Select(&g);
                 fclose(fp);
                 printf("input the rout needed to be expend\n");
                 printf("start:");  scanf("%d",&start);
                 printf("end:");  scanf("%d",&end);
                 printf("distence:");   scanf("%f",&distence);
                 printf("\n");
                 getchar();
                 add(&g,matrix,start,end,distence);
                 printf("now,the graph should be:\n");
                 test(&g,matrix);
                 getchar();
                 getchar();
                 break;


            }
            case 6:
            {
                 fp=fopen("graph.txt","rt");
                 read(&g,matrix,fp);
                 Select(&g);
                 fclose(fp);
                 printf("input the rout needed to be cut\n");
                 printf("start:");  scanf("%d",&start);
                 printf("end:");  scanf("%d",&end);
                 //printf("distence:");   scanf("%f",&distence);
                 printf("\n");
                 getchar();
                 cut(&g,matrix,start,end);
                 printf("now,the graph should be:\n");
                 test(&g,matrix);
                 getchar();
                 getchar();
                 break;
            }
            case 7:
            {
                  fp=fopen("graph.txt","wt");
                  creat_graph(&g,matrix,fp);
                  fclose(fp);
                  test(&g,matrix);
                  getchar();
                  break;

            }
            case 8:
            {
                  fp=fopen("graph.txt","rt");

                  read(&g,matrix,fp);
                  Select(&g);

                  fclose(fp);
                  add_point(&g,matrix);
                  test(&g,matrix);

                  getchar();
                  getchar();
                  break;
            }
            case 9:
            {
                  fp=fopen("graph.txt","rt");
                  read(&g,matrix,fp);
                  Select(&g);
                  fclose(fp);
                  //del_point(&g,matrix);
                  test(&g,matrix);
                  
                  getchar();
                  getchar();
                  break;
            }
        }
    }
       

}

    return 0;
}

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632