编一个图书信息管理管理系统,现在遇到一个问题卡住了,求解
现在的问题是将在控制台输入的数据读出到文档(txt格式)时,出现了乱码,但是出现乱码的又只是数字出现乱码,字母没有出现乱码,求解答现在将那个部分的函数代码放上来,望大神们帮忙解答解答一下吧,谢谢了~~
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
#include <ctype.h>
struct Books
{
int loginID,sortnum;
float price;
long time;
char bkname[50],cbname[50],wname[50];
struct books *next;
};
typedef struct Books Book;
Book books[20];
void homepage();
void adm_list();
void book_login();
void main()
{
char a;
int i;
printf("\n\n\t\t\t*****************************\n");
printf("\t\t\t 欢迎使用图书信息管理系统\n");
printf("\t\t\t*****************************\n\n\n");
printf("--------------------------------------------------------------------------------\n");
printf("\t <按回车键进入系统>\t");
a=getchar();
system("cls");
do{
printf("\n\n Management for Books' imformations:\n");
printf("\n\t 1.Input the book's information:\n");
printf("\t 2.Browse the book's information:\n");
printf("\t 3.Search the book's information:\n");
printf("\t 4.Delete the book's information:\n");
printf("\t 5.Change the book's information:\n");
printf("\t 6.EXIT!\n");
printf("\n\t Please input your choice:");
scanf("%d",&i);
system("cls");
if(i!=1 && i!=2 && i!=3 && i!=4 && i!=5 && i!=6)
{
printf("\n\tInput error!\n");
printf("\tEnter any key to start again!");
a=getchar();
}
}while(i!=1 && i!=2 && i!=3 && i!=4 && i!=5 && i!=6);
switch(i)
{
case 1: book_login(); break;
case 2: book_view(); break;
case 3: book_search(); break;
// case 4: del(); break;
// case 5: change(); break;
case 6: logout(); break;
}
}
/*----------------------------------------------------------------*/
void homepage()
{
char i;
printf("\n\n\t\t\t*****************************\n");
printf("\t\t\t 图书信息管理系统\n");
printf("\t\t\t*****************************\n\n\n");
printf(" -------------------------------------------------\n");
printf("\t<按任意键进入>\n\t");
i=getchar();
}
/*----------------------------------------------------------------*/
void adm_list()
{
void book_login();
void book_view();
void book_search();
void logout();
void del();
void change();
int i;
char a;
do{
printf("\n\n Management for Books' imformations:\n");
printf("\n\t 1.Input the book's information:\n");
printf("\t 2.Browse the book's information:\n");
printf("\t 3.Search the book's information:\n");
printf("\t 4.Delete the book's information:\n");
printf("\t 5.Change the book's information:\n");
printf("\t 6.EXIT!\n");
printf("\n\t Please input your choice:");
scanf("%d",&i);
system("cls");
if(i!=1 && i!=2 && i!=3 && i!=4 && i!=5 && i!=6)
{
printf("\n\tInput error!\n");
printf("\tEnter any key to start again!");
a=getchar();
}
}while(i!=1 && i!=2 && i!=3 && i!=4 && i!=5 && i!=6);
switch(i)
{
case 1: book_login(); break;
case 2: book_view(); break;
case 3: book_search(); break;
// case 4: del(); break;
// case 5: change(); break;
case 6: logout(); break;
}
}
void book_login()
{
struct Books Book;
void adm_list();
int i=0,j;
FILE *fp;
char a;
struct Books book_taxi[30];
printf("\n\n\n\t ---Please enter book's information---\n\n");
printf("\tLogin ID:");
scanf("%d",&Book.loginID);
printf("\n\tBook name:");
scanf("%s",Book.bkname);
printf("\n\tWriter's name:");
scanf("%s",Book.wname);
printf("\n\tSort number:");
scanf("%d",&Book.sortnum);
printf("\n\tPublishing company:");
scanf("%s",Book.cbname);
printf("\n\tPublishing time:");
scanf("%ld",&Book.time);
printf("\n\tBook's Price:");
scanf("%f",&Book.price);
system("cls");
if(fp!=NULL)
{
for(j=0;j<i;j++)
{
fprintf(fp,"%d\t",Book.loginID);
fprintf(fp,"%s\t",Book.bkname);
fprintf(fp,"%s\t",Book.wname);
fprintf(fp,"%d\t",Book.sortnum);
fprintf(fp,"%s\t",Book.cbname);
fprintf(fp,"%ld\t",Book.time);
fprintf(fp,"%f\t",Book.price);
fclose(fp);
}
}
fp=fopen("book.txt","r");
if(fp!=NULL)
{
for(j=0;j<i;j++)
{
fscanf(fp,"%d\t",&Book.loginID);
fscanf(fp,"%s\t",Book.bkname);
fscanf(fp,"%s\t",Book.wname);
fscanf(fp,"%d\t",&Book.sortnum);
fscanf(fp,"%s\t",Book.cbname);
fscanf(fp,"%ld\t",&Book.time);
fscanf(fp,"%f\t",&Book.price);
}
}
if((fp=fopen("book.txt","r"))==NULL)
{
fp=fopen("book.txt","w");
}
else
{
fclose(fp);
fp=fopen("book.txt","a");
}
fwrite(&Book,sizeof(struct Books),1,fp);
fclose(fp);
printf("\n\n\n\n\t The information has been stored,enter your choice to continue!\n\n");
printf("\n");
a=getchar();
adm_list();
fclose(fp);
}