当前位置: 代码迷 >> C语言 >> [求助]在线.
  详细解决方案

[求助]在线.

热度:431   发布时间:2006-11-25 16:52:04.0
[求助]在线.
#include<math.h>
typedef struct city
{
char name[10];
float x;
float y;
struct city *next;
}city;
city *p1,*p2;

void search(city *P1)
{
char name_search[10];
printf("please input city's name\n");
scanf("%s",name_search[10]);
while(1)
{
strcmp(name_search[10],P1->name[10]);
if(strcmp==0)
{
printf("P1->x\n");
printf("P1->y\n");
break;
}
else p1=p1->next;
}
}
void distance(city *q1)
{
float xm,yn,distance;
printf("please input the city's location\n");
scanf("%f,%f",&xm,&yn);
printf("please input the distance\n");
scanf("f%",&distance);
if((xm-q1->x)*(xm-q1->x)+(yn-q1->y)*(yn-q1->y)<sqrt(distance))
{
q1=q1->next;
}
else printf("q1->name\n");
}

main()
{char i;
int num,a;
{
printf("please input num of city");
scanf("%d",&num);
p1=p2=(struct city*)malloc(sizeof(city));
for(a=1;a<=num;a++)
{
p2=p1;
printf("please input information\n");
scanf("%s,%f,%f",&p1->name[10],&p1->x,&p1->y);
p2->next=p1;
p1=(struct city*)malloc(sizeof(city));
}
}
printf("please input your choice\n");
printf("(S)earch----------------(D)istance-----\n");
scanf("%c",&i);
switch(i)
{
case 'S':
case 's':search(p1);break;
case 'D':
case 'd':distance(p1);break;
default:printf("error\n");
}
}
运行编译都没问题.但用switch运行时直接跳出了.?大家帮忙看下.

搜索更多相关的解决方案: 在线  

----------------解决方案--------------------------------------------------------
以下是引用ar7043在2006-11-25 16:52:04的发言:
#include<math.h>
typedef struct city
{
char name[10];
float x;
float y;
struct city *next;
}city;
city *p1,*p2;

void search(city *P1)
{
char name_search[10];
printf("please input city's name\n");
scanf("%s",name_search[10]);
while(1)
{
strcmp(name_search[10],P1->name[10]);
if(strcmp==0)
{
printf("P1->x\n");
printf("P1->y\n");
break;
}
else p1=p1->next;
}
}
void distance(city *q1)
{
float xm,yn,distance;
printf("please input the city's location\n");
scanf("%f,%f",&xm,&yn);
printf("please input the distance\n");
scanf("f%",&distance);
if((xm-q1->x)*(xm-q1->x)+(yn-q1->y)*(yn-q1->y)<sqrt(distance))
{
q1=q1->next;
}
else printf("q1->name\n");
}

main()
{char i;
int num,a;
{
printf("please input num of city");
scanf("%d",&num);
p1=p2=(struct city*)malloc(sizeof(city));
for(a=1;a<=num;a++)
{
p2=p1;
printf("please input information\n");
scanf("%s,%f,%f",&p1->name[10],&p1->x,&p1->y);
p2->next=p1;
p1=(struct city*)malloc(sizeof(city));
}
}
printf("please input your choice\n");
printf("(S)earch----------------(D)istance-----\n");//下面的C就接收了这个.加个getchar().试试.
scanf("%c",&i);
switch(i)
{
case 'S':
case 's':search(p1);break;
case 'D':
case 'd':distance(p1);break;
default:printf("error\n");
}
}
运行编译都没问题.但用switch运行时直接跳出了.?大家帮忙看下.


----------------解决方案--------------------------------------------------------

  相关解决方案