C语言 求翻译 谢谢~

main()
{int t=1;
char str[10],code[]={"090212"};
while (t==1)
{printf("please enter the password:");
scanf("%s",str);
if(strcmp(str,code)==0)
Menu();
else
{
printf("Error,try again?(1-Yes/0-No)");
scanf("%d",&t);
while(t!=1&&t!=0)
{
printf("Error,try again?(1-Yes/0-No)");
scanf("%d",&t);
}
}
}
}
Menu()
{int a;
do{
do
{DisplayMenu();
scanf("%d",&a);
getchar();
switch (a)
{
case 0:printf("\nBye Bye\n");break;
case 1:InputInfo();break;
case 2:Search();break;
case 3:Modify();break;
case 4:Delete();break;
case 5:Display_in_price_order();break;
default:{printf("\nError,please choose again.\n");}
}
}while(a<0||a>5);
}while(a);
getch();
}

InputInfo()
{FILE *fp;
int i,j,c;
for(i=1;i<SIZE;i++)
{printf("\nPlease enter book's number:");
gets(book[i].num);
printf("\nPlease enter book's name:");
gets(book[i].name);
printf("\nPlease enter book's writer:");
gets(book[i].writer);
printf("\nPlease enter book's publisher:");
gets(book[i].pub);
printf("\nPlease enter book's price:");
scanf("%d",&book[i].price);
getchar();
printf("\nDo you want to continue?(1-YES/0-NO)");
scanf("%d",&c);
getchar();
if(c==0)break;
while(c!=1)
{printf("Error,try again?(1-Yes/0-No)");
scanf("%d",&c);
getchar();
}
}

if((fp=fopen("booklist","wb"))==NULL)
{printf("Error\n");
return;
}
for(j=0;j<=i;j++)
if(fwrite(&book[j],sizeof(struct book_type),1,fp)!=1)
printf("file write error\n");
fclose(fp);

你这个程序不全 差很多呀,这样有些变量和自定义函数的作用不是很确定,只能跟据英文意思差测下,已有的代码,我大概加了下注释,希望对你有用

main()
{int t=1;
char str[10],code[]={"090212"}; //设定密码为090212
while (t==1)
{printf("please enter the password:");
scanf("%s",str); //用户输入密码
if(strcmp(str,code)==0) //若输入的密码和设定的一样进入菜单
Menu();
else
{
printf("Error,try again?(1-Yes/0-No)"); //选一再次输入密码
scanf("%d",&t);
while(t!=1&&t!=0)
{
printf("Error,try again?(1-Yes/0-No)");//选一再次输入密码,选0退出,若不是0和1就提示再次输入
scanf("%d",&t);
}
}
}
}
Menu()
{int a;
do{
do
{DisplayMenu(); //显示菜单
scanf("%d",&a);
getchar(); //输入菜单前的数字
switch (a)
{
case 0:printf("\nBye Bye\n");break; //输入0,退出
case 1:InputInfo();break; //输入1,信息输入
case 2:Search();break; //查找
case 3:Modify();break; //修改
case 4:Delete();break; //删除
case 5:Display_in_price_order();break; //按价格展示
default:{printf("\nError,please choose again.\n");}//输入错误,重新输入
}
}while(a<0||a>5);
}while(a);
getch();
}

InputInfo() //信息输入函数
{FILE *fp; //定义一个文件指针
int i,j,c;
for(i=1;i<SIZE;i++)
{printf("\nPlease enter book's number:");//输入编号
gets(book[i].num);
printf("\nPlease enter book's name:");//输入书名
gets(book[i].name);
printf("\nPlease enter book's writer:");//输入作者
gets(book[i].writer);
printf("\nPlease enter book's publisher:");//输入出版社
gets(book[i].pub);
printf("\nPlease enter book's price:");//输入价格
scanf("%d",&book[i].price);
getchar();
printf("\nDo you want to continue?(1-YES/0-NO)");//是否继续输入
scanf("%d",&c);
getchar();
if(c==0)break;
while(c!=1)
{printf("Error,try again?(1-Yes/0-No)");//输入错误,再次输入
scanf("%d",&c);
getchar();
}
}

if((fp=fopen("booklist","wb"))==NULL) //向文件内写入书籍信息,打开文件,若失败提示错误
{printf("Error\n");
return;
}
for(j=0;j<=i;j++)
if(fwrite(&book[j],sizeof(struct book_type),1,fp)!=1)//写入信息失败,输出文件写入错误
printf("file write error\n");
fclose(fp); //关闭文件
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-06-06
好长啊,看看先
看了,c学得差,不懂

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网