Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Quad, aliswee), 835 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Unable to make new structures #485977
05/19/22 06:04
05/19/22 06:04
Joined: Apr 2022
Posts: 18
Singapore
V
vinitrinh Offline OP
Newbie
vinitrinh  Offline OP
Newbie
V

Joined: Apr 2022
Posts: 18
Singapore
Hi, I'm unable to make new structures and assign values to its attributes.

Problem 1: Unable to assign new attributes
Running the code below, the book title is empty for some reason.
Is there something wrong with the way I'm inserting the attribute value?
Code
typedef struct Books {
   char title[50];
} Book;

int main( ) {
   Book book;
   book.title =  "C Programming"; 
   printf( "Book title : %s\n", book.title);
   printf( "%s asd", book.title);
   return 0;
}


Zorro log:
Code
test_struct compiling........... ok

Book title :  asd


Problem 2: I'm unable to make a function that initializes these values for me

This is the code to repeat the error.
Code
typedef struct Books {
   char title[50];
} Book;
 
Book makeBook()
{
    Book book;
    book.title =  "C Programming"; 
    return book;
}

int main( ) {

   Book book = makeBook();
   printf( "Book title : %s\n", book.title);
   printf( "%s asd", book.title);
   return 0;
}


Error:
Code
test_struct compiling.........
Error in 'line 10: 
Syntax error: Wrong type SETRETV:::STRUCT@16
<     return book;
 >


Understand its slightly basic. But happy to receive any help on this.
Many thanks

Last edited by vinitrinh; 05/19/22 06:12.
Re: Unable to make new structures [Re: vinitrinh] #485979
05/19/22 10:30
05/19/22 10:30
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
The first is actually a string problem. You must use strcpy for char buffers:
https://zorro-trader.com/manual/en/str_.htm

For the second, Lite-C does not support returning structs. Lite-C does support pointers to structs as function arguments - use that instead.

Re: Unable to make new structures [Re: vinitrinh] #485982
05/20/22 12:08
05/20/22 12:08
Joined: Apr 2008
Posts: 585
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 585
Austria
List of C/C++ and lite-C differences:

https://zorro-project.com/manual/en/litec_c.htm


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1