帮我补个代码【程序设计】 --------------------------------------------------------- 题目:假设输入的是字母,若是大写字母输出1,小写字母输出0。 -------------------------------------------------------*/ #include <stdio.h> void bky(); int fun(char c) { /**********Begin**********/ /********** End **********/ } void main() { char c1; int c2; printf("Please input a char:\n"); c1=getchar(); c2=fun(c1); printf("%d\n",c2); bky(); } void bky() { FILE *IN,*OUT; int i; char iIN; int iOUT; IN=fopen("in.dat","r"); if(IN==NULL) { printf("Please Verify The Currernt Dir..it May Be Changed"); } OUT=fopen("out.dat","w"); if(OUT==NULL) { printf("Please Verify The Current Dir.. it May Be Changed"); } for(i=0;i<2;i++) { fscanf(IN,"%c",&iIN); iOUT=fun(iIN); fprintf(OUT,"%d\n",iOUT); } fclose(IN); fclose(OUT); }
时间: 2023-08-03 19:05:05 浏览: 106
将输入的大写字母改用小写字母输出
你可以这样实现fun函数:
```c
int fun(char c) {
if(c >= 'A' && c <= 'Z') {
return 1;
}
else {
return 0;
}
}
```
这里用到了ASCII码表中大写字母和小写字母的编码范围,如果c在大写字母的编码范围内,就返回1,否则返回0。
完整代码如下:
```c
#include <stdio.h>
int fun(char c) {
if(c >= 'A' && c <= 'Z') {
return 1;
}
else {
return 0;
}
}
void main() {
char c1;
int c2;
printf("Please input a char:\n");
c1=getchar();
c2=fun(c1);
printf("%d\n",c2);
bky();
}
void bky() {
FILE *IN,*OUT;
int i;
char iIN;
int iOUT;
IN=fopen("in.dat","r");
if(IN==NULL) {
printf("Please Verify The Currernt Dir..it May Be Changed");
}
OUT=fopen("out.dat","w");
if(OUT==NULL) {
printf("Please Verify The Current Dir.. it May Be Changed");
}
for(i=0;i<2;i++) {
fscanf(IN,"%c",&iIN);
iOUT=fun(iIN);
fprintf(OUT,"%d\n",iOUT);
}
fclose(IN);
fclose(OUT);
}
```
阅读全文