- 论坛徽章:
- 0
|
本帖最后由 txgc_wm 于 2013-04-25 23:23 编辑
示例代码如下:- #include<stdlib.h>
- #include<unistd.h>
- #include<string.h>
- #include<stdio.h>
- #define LETTER_MAX_LEN 256
- static int sunday(const char *src)
- {
- int i, len_d;
- int alphabet[LETTER_MAX_LEN] = {0};
- if(src == NULL)
- return -1;
- len_d = strlen(src);
- memset(alphabet, len_d, LETTER_MAX_LEN);
- /*for(i = 0; i < LETTER_MAX_LEN; i++)
- alphabet[i] = len_d;*/
- for(i = 0; i < LETTER_MAX_LEN; i++) {
- printf("%d ", alphabet[i]);
- if((i+1)%16 == 0)
- printf("\n");
- }
- return -1;
- }
- int main(int argc, char **argv)
- {
- sunday("lianghui");
- return 0;
- }
复制代码 当使用memset的时候,alphabet的值如下:- 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072
- 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072
- 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072
- 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072 134744072
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
复制代码 |
|