#include
#include
#include
#include
void wnz1();
void wnz2();
void wnz3();
void wnz4();
void main()
{
wnz1();
}
void wnz1()
{
int w1;
printf("plese select function:input:(1),statistics(2)");
scanf("%d",&w1);
if(w1==1)
wnz2();
else
wnz3();
}
void wnz2()
{
FILE *fp;
char str1[80],str[80];
if((fp=fopen("c:\statistics.txt","w+"))==NULL)
{
printf("Cannot open file \n\n");
exit(1);
}
printf("please input some charaters:\n");
scanf("%s",str1);
fprintf(fp,"%s",str1);
printf("%s",str1);
/* do
{
printf("ok");
gets(str);
if(*str!='\n')
{
strcat(str,"\n");
fputs(str,fp);}
if(*str!='\n')
break;
}while(*str!='\n');*/
/* int k;
for(k=0;k<80;k++)
{
getchar(str1[k]);
fputc(str[k],fp);
if(*str!='\n') break;
}*/
fclose(fp);
wnz4();
}
void wnz3()
{
FILE *fp1;
char ch[80];
int k,len;
int a=0,b=0,c=0,d=0;
if((fp1=fopen("c:\statistics.txt","r"))==NULL)
{
printf("Cannot open file\n\n");
exit(1);
}
while(!feof(fp1))
{
fgets(ch,80,fp1);
}
len=strlen(ch);
for(k=0;k
{
if(true)
{
if((ch[k]>='a'&&ch[k]<='z')||(ch[k]>='A'&&ch[k]<='Z'))
a++;
if(ch[k]==' ')
b++;
if(ch[k]>='0'&&ch[k]<='9')
c++;
}
else
d++;
}
printf("The statistics is as follow:\n");
printf("len:%d\n",len);
printf("char: %d\nspace: %d\ndigit : %d\nothers :%d\n",a,b,c,d);
fclose(fp1);
wnz4();
}
void wnz4()
{
char w[4];
printf("continue?(Yes or No)");
scanf("%s",w);
if(strchr("yesYES",*w))
wnz1();
if(strchr("noNO",*w))
exit(1);
printf("please enter (Yes or No)");
wnz4();
}
我想往文件里输入空格和特殊字符用fprintf做不到.但可以输入字母和数字可以统计出来
但我用gets(str);
fputs(str,fp);
又什么都不能输入,直接进入了下一个程序 奇怪
就是我封的那一个

被折叠的 条评论
为什么被折叠?



