- 论坛徽章:
- 0
|
本帖最后由 Magic_LP 于 2010-06-14 00:27 编辑
代码本身有问题。你看这样行不行- #include <stdio.h>
- #include <string.h>
- #define USER_LEN 33
- #define PASSWORD_LEN 33
- #define ACOUNT_NUM 10
- typedef struct _a{
- char user[USER_LEN];
- char password[PASSWORD_LEN];
- int authority;
- }Acount_t;
- static Acount_t acounts[ACOUNT_NUM];
- void fun(void *s)
- {
- Acount_t *u;
- u = (Acount_t *)s;
- strncpy(u[0].user, "admin1", USER_LEN);
- strncpy(u[1].user, "admin2", USER_LEN);
- /*或者
- strncpy(u->user, "admin1", USER_LEN);
- strncpy((u+1)->user, "admin2", USER_LEN);
- */
- }
- int main(int argc, char *argv[])
- {
- memset(&acounts, 0, sizeof(Acount_t)*ACOUNT_NUM);
- fun((void *)&acounts);
- printf("acounts[0].user = |%s|,acounts[1].user = |%s|\n",
- acounts[0].user, acounts[1].user);
- return 0;
- }
复制代码 |
|