c语言字母数字和特殊字符,一个统计输入文件中字符,空格,数字,和特殊字符的代码,不过有点问题(请教)...

#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);

又什么都不能输入,直接进入了下一个程序 奇怪

就是我封的那一个

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值