c语言导入txt文本乱码
求解
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
# define size 2
struct t_type
{
int b;/*班次 */
char f[5];/*起飞时间*/
char q[20];/*起点站*/
char z[20];/*终点站*/
int x;/*飞行时间*/
int e;/*额定载量*/
int y;/*已定票人数*/
} ;
FILE *fp;
void input() /*录入班次信息*/
{ struct t_type t[size];
int i;
if((fp=fopen("titcket.txt","w+"))==NULL)
{printf("打开数据库未成功\n");
exit(0);
}
printf(" 请录入班次信息: \n");
for(i=0;i<1;i++)
{
scanf("%d",&t[i].b);
scanf("%s",t[i].f);
scanf("%s",t[i].q);
scanf("%s",t[i].z);
scanf("%d",&t[i].x);
scanf("%d",&t[i].e);
scanf("%d",&t[i].y);
}
for(i=0;i<size;i++)
{
fwrite(&t[i],sizeof( struct t_type),1,fp);
}
fclose(fp);
}
void output() /*浏览班次信息*/
{int i=0;
struct t_type t[size];
if((fp=fopen("titcket.txt","r"))==NULL)
{printf("打开数据库未成功\n");
exit(0);
}
for(i=0;i<1;i++)
{fread(&t[i],sizeof(struct t_type),1,fp);
printf("\n%d %s %s %s %d %d %d \n",t[i].b,t[i].f,t[i].q,t[i].z,t[i].x,t[i].e,t[i].y);
}
fclose(fp);
}
void check1( ) /*按班次查询*/
{ int j;int b;
struct t_type t[size];
if((fp=fopen("titcket.txt","r"))==NULL)
{printf("not open the file\n");
exit(0);
}
for(j=0;j<size;j++)
fread(&t[j],sizeof(struct t_type),1,fp);
printf(" 请输入你想要查询的班次号:\n");
scanf("%d",&b);
for(j=0;j<size;j++)
if(b==t[j].b)
{printf("\n%d %s %s %s %d %d %d \n",t[j].b,t[j].f,t[j].q,t[j].z,t[j].x,t[j].e,t[j].y);
break;
}
if(j>=size)
printf("对不起,没有此次飞机,谢谢使用!\n");
fclose(fp);
}
void check2( ) /*按终点站查询*/
{int j;char z[20];
struct t_type t[size];
if((fp=fopen("titcket.txt","r"))==NULL)
{printf("not open the file\n");
exit(0);
}
for(j=0;j<size;j++)
fread(&t[j],sizeof(struct t_type),1,fp);
printf(" 请输入你想要查询终点站的名称:\n");
scanf("%s",z);
for(j=0;j<size;j++)
if(strcmp(z,t[j].z )==0)
{printf("\n%d %s %s %s %d %d %d \n",t[j].b,t[j].f,t[j].q,t[j].z,t[j].x,t[j].e,t[j].y);break;
}
if(j>=size)
printf("对不起,没有此次飞机,谢谢使用!\n");
fclose(fp);
}
void order ( ) /*订票*/
{ int i,b,m;char z[20];int flag=1;
struct t_type t[size];
if((fp=fopen("titcket.txt","r"))==NULL)
{printf("not open the file\n");
exit(0);
}
for (i=0;i<=1;i++)
fread(&t[i],sizeof(struct t_type),1,fp);
printf("\n请输入要到达的终点站:\n");
scanf("%s",z);
printf("到达此终点站的车次有:\n");
printf("\n班次.发车时间. 起点站 . 终点站. 行车时间. 额定载量. 已定票人数 \n");
for(i=0;i<=1;i++)
if(strcmp(z,t[i].z )==0)
{flag=2;
printf("\n%d %s %s %s %d %d %d \n",t[i].b,t[i].f,t[i].q,t[i].z,t[i].x,t[i].e,t[i].y);
}
for(i=0;i<=1;i++)
if(strcmp(z,t[i].z )==0)
if(t[i].y<t[i].e)
{flag=3;
printf("请输入定票的车次:\n");
scanf("%d",&b);
printf("请输入订票的张数:\n");
scanf("%d",&m);
for(i=0;i<=size;i++)
if(b==t[i].b)
{t[i].y=t[i].y+m;
printf("此班次的飞机当前信息为:\n");
printf("\n班次.起飞时间. 起点站 . 终点站. 飞行时间. 额定载量. 已定票人数 \n");
printf("\n%d %s %s %s %d %d %d \n",t[i].b,t[i].f ,t[i].q,t[i].z,t[i].x,t[i].e,t[i].y);
}
}
if(flag==1)
printf("\n没有此班次飞机,请查询后重新输入\n");
if(flag==2)
printf("票已售完\n");
fclose(fp);
if((fp=fopen("titcket.txt","w"))==NULL)
{printf("not open the file\n");
exit(0);
}
for (i=0;i<=size;i++)
fwrite(&t[i],sizeof(struct t_type),1,fp);
fclose(fp);
}
void rback() /*退票*/
{int b,i,m;
struct t_type t[size];
if((fp=fopen("titcket.txt","r"))==NULL)
{ printf("not open the file\n");
exit(0);
}
for(i=0;i<=1;i++)
fread(&t[i],sizeof(struct t_type),1,fp);
printf("请输入退票的班次:\n");
scanf("%d",&b);
printf("请输入退票的张数:\n");
scanf("%d",&m);
for(i=0;i<=size;i++)
if(b==t[i].b)
{t[i].y=t[i].y-m;
printf("\n班次.起飞时间. 起点站 . 终点站. 飞行时间. 额定载量. 已定票人数 \n");
printf("\n%d %s %s %s %d %d %d \n",t[i].b,t[i].f ,t[i].q,t[i].z,t[i].x,t[i].e,t[i].y);}
if(i>=size)
printf("对不起,没有此飞机票信息,请查询后再次输入!\n");
fclose(fp);
if((fp=fopen("titcket.txt","w"))==NULL)
{printf("not open the file\n");
exit(0);
}
for (i=0;i<=size;i++)
fwrite(&t[i],sizeof(struct t_type),1,fp);
fclose(fp);
}
void menu()
{ int a;
printf(" 机票管理系统\n");
printf(" 制作人:****\n");
printf(" 制作时间:2014年6月\n");
printf("\n=======================================\n");
printf(" 1、录入机票信息\n");
printf(" 2、浏览机票信息\n");
printf(" 3、按班次查询\n");
printf(" 4 按终点站查询\n");
printf(" 5、订票\n");
printf(" 6、退票信息\n");
printf(" 7、退出该系统\n");
printf("\n=======================================\n");
while(1){
printf("请选择你所需要的功能:");
scanf("%d",&a);
switch(a)
{
case 1: input(); break;/*录入班次信息*/
case 2: output(); break;/*浏览班次信息*/
case 3: check1(); break;/*按班次查询路线*/
case 4: check2(); break;/*按终点站查询路线*/
case 5: order(); break;/*订票*/
case 6: rback(); break;/*退票信息*/
case 7:printf("\n***********************谢谢使用本系统,欢迎下次继续使用************************\n"); break;/*退出系统*/
}
if(a==7) break;
}
}
main()//警告可以忽略
{ menu();
getch();
}