typedef struct bus
{
int num; //公交車路線編號
struct Bus* next; //公交車站點連接
char name[10]; //站點名字
}bus;
//創建公交車線路
bus* creat()
{
bus* head, * p, * pr;
char ch = ' ';
head = pr=(bus*)malloc(sizeof(bus));
pr->next = NULL;
printf("請輸入公交車的線路的編號:");
scanf("%d", &head->num);
printf("請輸入車站:");
while (ch!='\n')
{
p = (bus*)malloc(sizeof(bus));
if (head == NULL)
{
head = p;
}
else
{
pr->next = p;
pr = p;
}
char chance[10];
scanf("%s", p->name);
ch = getchar();
}
pr->next = NULL;
//將資訊存入檔案
bus* new = head;
FILE* fp;
fp = fopen("C:\\Users\\Fanyupei\\Desktop\\bus.txt", "a");
if (fp == NULL)
{
printf("檔案打開失敗!");
exit(0);
}
//將線路資訊回圈輸入
fprintf(fp, "%d ", new->num);
while (new->next != NULL)
{
printf("%s", new->name);
fprintf(fp, "%s", new->name);
new = new->next;
}
fclose(fp);
return head;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/278205.html
標籤:C語言
上一篇:萌新想求助一下大佬們
下一篇:修改程式:日期類及加1天函式實作
