在TC中~#include#include#include#include#includecharstr[10];staticcharstr2[10]="1234";structstudent{intnum;char*name;longphone...
在TC中~
#include
#include
#include
#include
#include
char str[10];
static char str2[10]="1234";
struct student
{
int num;
char *name;
long phone;
char *homework;
};
student stu1;
void input()
{
FILE *fp;
if((fp=fopen("D:\\stu1.txt","at+"))==NULL)
{
printf("Cannot open file,strike any key exit!");
getch();
exit(1);
}
printf("please input the student's information:\n");
printf("input student's num:\n");
scanf("%d",&stu1.num);
if(stu1.num!=0)
{
printf("input student's name:\n");
scanf("%s",stu1.name);
printf("input student's phone:\n");
scanf("%ld",&stu1.phone);
printf("input student's homework:\n");
scanf("%s",stu1.homework);
fprintf(fp," %d\n %s\n %ld\n %s\n",stu1.num,stu1.name,stu1.phone,stu1.homework);
}
else
{
printf("the end of the input!\n");
}
fclose(fp);
getch();
}
void output()
{
printf("stu1 num:");
printf("%d\n",stu1.num);
printf("stu1 name:");
printf("%s\n",stu1.name);
printf("stu1 phone:");
printf("%ld\n",stu1.phone);
printf("stu1 homework:");
printf("%s\n",stu1.homework);
getch();
}
void view_key()
{
printf("the key is:");
printf("%s\n",str2);
getch();
}
void change_key()
{
printf("the old key is 1 2 3 4.\n");
printf("Now please enter the new key:\n");
scanf("%s",str2);
printf("Now the new key is:\n");
printf("%s\n",str2);
getch();
}
void main()
{
laber:;
printf("please enter key:\n");
scanf("%s",str);
if(strcmp(str,str2)==0)
{
printf("please enter key again:\n");
scanf("%s",str);
if(strcmp(str,"1234")==0)
{
printf("please enter key the last time:\n");
scanf("%s",str);
if(strcmp(str,"1234")==0)
{
printf(" welcome to this system >_
printf("_________________________________________\n");
}
else goto laber;
}
else goto laber;
}
else goto laber;
toutou:;
int key;
printf(" 1--------input student information\n");
printf(" 2--------output student information\n");
printf(" 3--------view the key for tnis systerm\n");
printf(" 4--------change the key for this systerm\n");
printf(" 5--------you can leave the systerm\n");
printf(" -------------please enter your desition\n");
scanf("%d",&key);
switch(key)
{
case 1:
printf("Now,you can input one student information:\n");
input();
break;
case 2:
printf("Now,you can output student information:\n");
output();
break;
case 3:
printf("Now,you can view the key for this systerm:\n");
view_key();
break;
case 4:
printf("Now,you can change the key for this systerm:\n");
change_key();
break;
case 5:
printf("Now,you can leave the systerm!");
goto loop;
default:
printf("your decision is wrong --!\n");
}
goto toutou;
loop:;
getch();
}
展开
c语言将数据写入文件后乱码_C语言中写入文件的字符数组为乱码 但整形数据却正常!!!...