急急急!!帮忙解决一道编程题,加20分!从键盘输入一串字符,并以*结束将其中小写字母全部...

来源:百度知道 编辑:UC知道 时间:2024/05/13 09:23:11
从键盘输入一串字符,并以*结束.将其中小写字母全部转换为大写字母,然后输出到磁盘文件”test.dat”中保存.

C语言写的

void main()
{
FILE *f;
char c[50];
int i;
printf("input string:\n");
for(i=0;i<49;i++)
{
c[i]=getchar();
if(c[i]=='*')
break;
if(c[i]>='a' && c[i]<='z')
c[i]=c[i]-'a'+'A';
}
c[i+1]='\0';

if((f=fopen("test.dat","wb"))==NULL)
{
printf("cannot open file!\n");
exit(0);
}
else
{
fputs(c,f);
}

fclose(f);
getch();
}