c语言导入txt文本乱码

baidu_16916719 2014-06-28 08:50:49
求解
#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();
}
...全文
443 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wen_eric 2014-06-28
  • 打赏
  • 举报
回复
up
The_Third_Wave 2014-06-28
  • 打赏
  • 举报
回复
引用 6 楼 baidu_16916719 的回复:
引用 1 楼 u013171165 的回复:
统一文件编码,IDE console编码,没其他选择。
在哪修改呀 能指出吗
你的IDE你自己改,另外,我是建议所有都用utf-8编码,这样中文注释跨平台才不会消失。
baidu_16916719 2014-06-28
  • 打赏
  • 举报
回复
引用 1 楼 u013171165 的回复:
统一文件编码,IDE console编码,没其他选择。
在哪修改呀 能指出吗
baidu_16916719 2014-06-28
  • 打赏
  • 举报
回复
引用 3 楼 zxh707wk 的回复:
这种事。。。 当我把在linux下写的代码放到windows上打开时中文会乱码。。。
环境实在win 的呀 怎么修改呢
baidu_16916719 2014-06-28
  • 打赏
  • 举报
回复
怎么修改呢 在哪部分修改?
707wk 2014-06-28
  • 打赏
  • 举报
回复
这种事。。。 当我把在linux下写的代码放到windows上打开时中文会乱码。。。
TreeCare 2014-06-28
  • 打赏
  • 举报
回复
编码不一样吧,比如说txt文件中有的符号编码在你运行条件下没有对应的符号,于是对应的是乱码。换个条件试试。
The_Third_Wave 2014-06-28
  • 打赏
  • 举报
回复
统一文件编码,IDE console编码,没其他选择。
707wk 2014-06-28
  • 打赏
  • 举报
回复
引用 7 楼 u013171165 的回复:
引用 6 楼 baidu_16916719 的回复:
[quote=引用 1 楼 u013171165 的回复:] 统一文件编码,IDE console编码,没其他选择。
在哪修改呀 能指出吗
你的IDE你自己改,另外,我是建议所有都用utf-8编码,这样中文注释跨平台才不会消失。[/quote]+1

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧