//将ss所指字符串中所有下标为奇数位上的字母转换成大写,若不是字母,则不转换。
1 #include <stdio.h> 2 #include <string.h> 3 void fun ( char *ss ) 4 { 5 while(*ss) 6 { 7 ss++; 8 if (*ss >= 'a'&&*ss <= 'z') 9 { 10 *ss -= 32;//转化为小写 11 } 12 ss++; 13 } 14 } 15 16 void main( ) 17 { char tt[81] ; 18 void NONO ( ); 19 printf( " Please enter an string within 80 characters: " ); gets( tt ); 20 printf( " After changing, the string "%s"", tt ); 21 fun( tt ); 22 printf( " becomes "%s" ", tt ); 23 NONO ( ); 24 } 25 26 void NONO ( ) 27 {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ 28 FILE *fp, *wf ; 29 char tt[81] ; 30 int i ; 31 32 fp = fopen("in.dat","r") ; 33 wf = fopen("out.dat","w") ; 34 for(i = 0 ; i < 10 ; i++) { 35 fscanf(fp, "%s", tt) ; 36 fun( tt ) ; 37 fprintf(wf, "%s ", tt) ; 38 } 39 fclose(fp) ; 40 fclose(wf) ; 41 }
//利用数组解决。
1 void fun ( char *ss ) 2 { 3 for (int i = 1; ss[i] != '