Thread: return type: struct

  1. #1
    Registered User lliero's Avatar
    Join Date
    Oct 2001
    Posts
    59

    return type: struct

    guys,,
    why does this code does'nt work



    #include<stdio.h>

    struct emp{
    char name[80];
    };


    main(){
    struct emp e;
    e=data();
    }

    emp data(){
    struct emp e;
    strcpy(e.name,"test");
    return e;
    }


    please help me...

    i really need to finished this part on my programm...
    tnx




    how can i return emp struct from data function?
    " programming is 1% syntax and 99% logic "

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code:
    #include<stdio.h>
    #include <string.h>
    
    struct emp
    { 
      char name[80]; 
    }; 
    
    struct emp data ( void )
    { 
      struct emp e; 
      strcpy(e.name,"test"); 
      return e; 
    }
    
    int main ( void )
    { 
      struct emp e; 
      e = data();
      return 0;
    }
    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User lliero's Avatar
    Join Date
    Oct 2001
    Posts
    59

    tnx alot

    hahahahhaha



    yea.. your right.. i forgot to do that..
    i was a bit involve with c++...

    yea your right ..



    thnx alot man
    " programming is 1% syntax and 99% logic "

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. 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
  3. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM