1.#include<stdio.h> main() |
|
10分 |
1.修改如下:
#include<stdio.h> void fun(char x[5][10], int n) { x[n][0] = 0; } int main() { char x[5][10] = { "create","modify","sort","skip","delete" }; int i; printf("the original string:\n"); for (i = 0; i<5; i++) puts(x[i]); printf("\n"); printf("the string after delect:\n"); fun(x, 4); for (i = 0; i<5; i++) puts(x[i]); printf("\n"); return 0; } |
10分 |
2.这样可好:
int i, pos1, pos2, n; unsigned char bm[32]; int main(void) { char *s = "beijing"; n = strlen(s); memset(bm, 0, 32); for (i = 0; i < n; i++) { pos1 = s[i] / 8; pos2 = s[i] % 8; if (0 == (bm[pos1] & (1u << pos2))) { bm[pos1] |= 1u << pos2; } else { printf("%c\n", s[i]); break; } } if (i == n) printf("non a character occurs twice!\n"); return 0; } |
10分 |
正确来讲,是第一个出现两次以上的字符
|
另一个问题
#include<stdio.h> char *fun(char *p) { int i,j=0; char *q=p; for(i=0;i<20;i++) { if(“”0″”<=q[i]&&q[i]<=””9″”) p[j++]=q[i]; } for(i=0;i<20;i++) { if(“”0″”<=q[i]&&q[i]<=””9″”) continue; else p[j++]=q[i]; } return(p);//为什么不能返回局部变量q的地址 return(q);//为什么不能返回局部变量q的地址,如果在前一句加p=q;返回q也是错误的,为什么? char s[20]=”asd123fgh5##43df”;//为什么输出为123543fgh##df printf(“%s\n”,b); |
|
10分 |
char *q=p; // 这样写 return q; |