|
发表于 2002-12-24 15:23:24
|
显示全部楼层
正确代码如下:
#include "stdio.h"
#include "conio.h"
#include "string.h"
void main(void)
{
char a[20],b[20];
FILE *fp;
fp=fopen("code.txt","r");
if(fp==NULL)
{
printf("\nfile cannot open");
getch();
}
printf("\nplease input the code:");
scanf("%s",b);
fread(a,strlen(b),1,fp);
////////////// 注意:下面这句不要忘记!字符串一定要以0字符结尾!
a[strlen(b)]=0;
//////////////
if(strcmp(b,a)==0)
{
printf("\nthe code is right!");
getch();
}
else
{
printf("\nwrong code!");
}
printf("%s",a);
getch();
}
|
|