Thread: Return struct

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    270

    Question Return struct

    How can i return a structure, I have tried this:
    Code:
    #include <stdio.h>
    
    struct list 
    {
    	int one, two=0;
    };
    typedef struct list item;
    
    int main()
    {
    	item thingM;	
    	thingM = funct();
    	printf("%d\n", thingM.one);
    }
    
    item funct()
    {
    	item thing;
    	thing.one = 10;
    	return thing;
    }
    But i get the error message:
    Code:
    new.c:5: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token
    new.c: In function ‘main’:
    new.c:12: error: incompatible types in assignment
    new.c: At top level:
    new.c:16: error: conflicting types for ‘funct’
    new.c:12: error: previous implicit declaration of ‘funct’ was here
    Last edited by taurus; 10-02-2009 at 10:16 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Circularly-Doubly Linked List implementation
    By BlackOps in forum C Programming
    Replies: 4
    Last Post: 07-19-2009, 04:45 AM
  2. Converting from C to C++
    By Taka in forum C++ Programming
    Replies: 5
    Last Post: 04-08-2009, 02:16 AM
  3. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  4. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  5. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 07:57 AM