Beginners_-_strcpy_struct_char.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "raylib.h"
  2. #include "string.h"
  3. typedef struct book{
  4. char name[20];
  5. }book;
  6. int main(void)
  7. {
  8. // Initialization
  9. //--------------------------------------------------------------------------------------
  10. const int screenWidth = 800;
  11. const int screenHeight = 450;
  12. InitWindow(screenWidth, screenHeight, "raylib example.");
  13. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  14. //--------------------------------------------------------------------------------------
  15. struct book mybook;
  16. strcpy(mybook.name,"Title!");
  17. // Main game loop
  18. while (!WindowShouldClose()) // Detect window close button or ESC key
  19. {
  20. // Update
  21. //----------------------------------------------------------------------------------
  22. //----------------------------------------------------------------------------------
  23. // Draw
  24. //----------------------------------------------------------------------------------
  25. BeginDrawing();
  26. ClearBackground(RAYWHITE);
  27. DrawText(FormatText("Contents of name = %s",mybook.name),200,100,20,GRAY);
  28. EndDrawing();
  29. //----------------------------------------------------------------------------------
  30. }
  31. // De-Initialization
  32. //--------------------------------------------------------------------------------------
  33. CloseWindow(); // Close window and OpenGL context
  34. //--------------------------------------------------------------------------------------
  35. return 0;
  36. }