[LCP]passing struct to function

Greg Black gjb at gbch.net
Sun Nov 21 09:28:01 UTC 2004


On 2004-11-20, Carlos Pruitt, Jr. wrote:
> 
> I am trying to find what I am doing wrong.  This program compiles with 
> the warning message:
> 
> warning: passing arg 1 of `print_mailing_list' from incompatible pointer 
> type
> 
> When I run the program, the output is:
> 
> f at carlos
> 
> 
> #include <stdio.h>
> #include <string.h>
> 
> struct mailing
> {
>        char first_name[60];
> };
> 
> void print_mailing_list(struct mailing *mlist)
> {
>        printf("%s\n", mlist->first_name);
> }
> 
> int main()
> {
>        struct mailing list =
>                {
>                        "carlos"
>                };
> 
>        struct mailing *list_ptr;

Delete the line above; you don't use this variable anywhere so
it is not needed.

>        if (strcmp(list.first_name, "carlos") == 0)
>                print_mailing_list(&list_ptr);

Change the above to:

                 print_mailing_list(&list);

> 
>        return 0;
> 
> }

Compile, test.  Then study and understand.

Greg




More information about the linuxCprogramming mailing list