为什么这个c语言输不出结果? 100
#include<stdio.h>#include<stdlib.h>#include<math.h>#include<assert.h>doubledistance(d...
#include <stdio.h>#include <stdlib.h>#include <math.h>#include <assert.h>double distance(double Cust_lng, double Cust_len, double Machine_lng, double Machine_len);struct hunman{ //声明基站与客户的基本属性 double lng; //经度 double len; //维度 char name[50]; //名称} Cust[85208], Mathine[59228], End[85208], *Cust_Define, *Mathine_Define, *End_Define;int main(){ FILE *Cust_File, *Mathine_File, *End_File;//声明文件地址 Cust_Define = Cust; Mathine_Define = Mathine; End_Define = End;//初始化基站与用户、最终结果 int num = 0; //用于计算最终结果有多少个 Mathine_File = fopen("user副本.txt","r+"); if (Mathine_File == NULL){ //输入基站文件地址 puts("Fail to open Mathine's file"); exit(0); } for(int i = 0; i < 59228; i++,Mathine_Define++){ //读入基站数据 fscanf(Mathine_File, "| %lf,%lf |\n", Mathine_Define->lng, Mathine_Define->len); } Cust_File = fopen("工作簿2_84.txt","r+"); if (Cust_File == NULL){ //输入客户文件地址 puts("Fail to open Cust's File"); exit(0); } for(int i = 0; i < 85208; i++,Cust_Define++){ //读入客户数据 fscanf(Cust_File, "%lf %lf %s\n", Cust_Define->lng, Cust_Define->len, Cust_Define->name); printf("%lf, %lf, %s\n", Cust_Define->lng, Cust_Define->len, Cust_Define->name); } End_File = fopen("符合结果.txt","r+"); if (End_File == NULL){ //输入最终结果文件地址 puts("Fail to open End's File"); exit(0); } for(int i = 0; i < 85208; i++){ //通过两个 for 循环,判断是否被基站信号范围覆盖 for(int j = 0; j <59228; j++){ if(distance(Cust[i].lng, Cust[i].len, Mathine[j].lng, Mathine[j].len) < 500.0){ Cust[i].lng = End[num].lng; Cust[i].len = End[num].len; for(int k = 0; k < 20; k++){ //复制名字 Cust[i].name[k] = End[num].name[k]; } num++; //计数加一 } } } for(int i = 0; i < num; i++,End_Define++){ //输出最终结果到文本 fprintf(End_File, "%lf, %lf, %s\n", End_Define->lng, End_Define->len, End_Define->name); printf("%lf,%lf,%s\n", &End_Define->lng, &End_Define->len, &End_Define->name); } fclose(End_File); fclose(Cust_File); fclose(Mathine_File); return 0;}//计算两者距离double distance(double Cust_lng, double Cust_len, double Machine_lng, double Machine_len){ double length = sqrt((Cust_lng - Machine_lng)*(Cust_lng - Machine_lng)+(Cust_len - Machine_len)*(Cust_len - Machine_len)); return length;}
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询