C语言,哪错了?

来源:百度知道 编辑:UC知道 时间:2024/05/04 23:56:13
下面的程序哪错了啊?谢谢拉啊~~~~~~

#define N 10
#include<stdio.h>
#include<string.h>
main()
{FILE *fcai;
int a[N],b[N],*p,i=0,j,n,m=0,mm=0,flag=1;
if((fcai=fopen("c:\\cai.txt","a+"))==NULL)
{printf("you haven't gave a number OR can not open file\n");
exit(0);}
fscanf(fcai,"%s",p);
if((n=strlen(p))>N)
{printf("this is a wrong number,please input another number that every bit are different");
exit(0);}
else printf("longth of this number is %d\n",n);
while(!feof(fcai))
{a[i]=fgetc(fcai);i++;}
printf("A is there have how many bit are right\nB is there have how many bit in this number but place are wrong\n");
while(flag)
{printf("please input a number that has %d bit:\n",n);
for(i=0;i<n;i++)
scanf("%c",&b[i]);
for(j=0;j<n;j++)
for(i=0;i&

错在
int *p;

应声明为 char p[100];
fscanf(fcai,"%s",p); 改为 fscanf(fcai,"%s",&p[0]);

%s 对应的p应是char.

用char*存字符串时要已分配了存储单元.
用char p[100]; 比较简单.