Beginners_-_String_inside_char.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "raylib.h"
  2. int main(void)
  3. {
  4. // Initialization
  5. //--------------------------------------------------------------------------------------
  6. const int screenWidth = 800;
  7. const int screenHeight = 450;
  8. InitWindow(screenWidth, screenHeight, "raylib example.");
  9. // The last number of the char array[5] contains the ending code.
  10. char messy[6] = "hello";
  11. // We need to set up the char that contains the text with a lenght.
  12. int lenofmessy = 6;
  13. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  14. //--------------------------------------------------------------------------------------
  15. // Main game loop
  16. while (!WindowShouldClose()) // Detect window close button or ESC key
  17. {
  18. // Update
  19. //----------------------------------------------------------------------------------
  20. //----------------------------------------------------------------------------------
  21. // Draw
  22. //----------------------------------------------------------------------------------
  23. BeginDrawing();
  24. ClearBackground(RAYWHITE);
  25. // Here we draw the char!
  26. DrawText(messy,100,100,20,BLACK);
  27. // Draw the string(the char array) backwards.
  28. for(int i=lenofmessy-1;i>-1;i--){
  29. DrawText(FormatText("%01c",messy[i]),100+(((lenofmessy-2)*20)-(i*20)),120,20,BLACK);
  30. }
  31. EndDrawing();
  32. //----------------------------------------------------------------------------------
  33. }
  34. // De-Initialization
  35. //--------------------------------------------------------------------------------------
  36. CloseWindow(); // Close window and OpenGL context
  37. //--------------------------------------------------------------------------------------
  38. return 0;
  39. }