warning: assignment from incompatible pointer type

OP (Company: no) #5067690
I'm sick of this warning! Here's the code
1
struct passwd *pwd; 
2

3
code In function printLine:
4
gid_t gid = statbuf.st_gid;
5
        pwd = getgrgid(gid);
6
        if(pwd != NULL)
7
            printf("%s]", pwd->pw_name);
8
        else
9
            printf("%d]", statbuf.st_gid);
All prints correctly when executed. What needs to be corrected so that 
the selection disappears?
====
ls.c: In function ‘printLine’:
ls.c:225:13: warning: assignment from incompatible pointer type
         pwd = getgrgid(gid);
             ^
Moderator #5067781
pwd seems to be of type

  struct passwd *

but getgrgid() returns

  struct group *

The first three elements of the two structs are similar, thus the code
still works.

Reply

A question of your own? This thread is over 9 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.