- 论坛徽章:
- 0
|
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <pwd.h>
5 #include <grp.h>
6 #include <sys/types.h>
7
8 void usage( char *name )
9 {
10 printf("usage: %s username/useID \n",name);
11 }
12 int main( int argc, char **argv )
13 {
14 struct passwd *pwd;
15 struct group *grp;
16 char **namelist;
17 pwd=malloc(sizeof(struct passwd));
18 grp=malloc(sizeof(struct group));
19 int i;
20 if (argc != 2)
21 usage( argv[0] );
22 if (pwd = getpwnam(argv[1])==NULL)
23 {
24 if ((pwd = getpwuid(atoi(argv[1])))==NULL)
25 {
26 printf("error: username or user ID \n");
27 exit(1);
28 }
29 }
30 printf("user name: %s\n",pwd->pw_name);
31 printf("user password: %s\n",pwd->pw_passwd);
32 printf("user ID: %d\n",pwd->pw_uid);
33 printf("user GID: %d\n",pwd->pw_gid);
34 printf("user Dir: %s\n",pwd->pw_dir);
35 printf("user shell: %s \n",pwd->pw_shell);
36 printf("user gecos: %s \n",pwd->pw_gecos);
37 if (grp = getgrgid(pwd->pw_gid) == NULL)
38 {
39 printf("error:getgrgid\n");
40 exit(1);
41 }
42 printf("group name: %s\n",grp->gr_name);
43 printf("group password: %s\n",grp->gr_passwd);
44 printf("group member: \n");
45 for (i=0; namelist[i]!=NULL; i++)
46 {
47 printf("\t%s\n",namelist[i]);
48 }
49 exit(0);
50 }错误提示:
#gcc -o userlist a.c
a.c: In function `main':
a.c:22: warning: assignment makes pointer from integer without a cast
a.c:37: warning: assignment makes pointer from integer without a cast |
|