2
0

Beginners_-_LoadFileText_SaveFileText.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "raylib.h"
  2. #include "string.h"
  3. int main(void)
  4. {
  5. // Initialization
  6. //--------------------------------------------------------------------------------------
  7. const int screenWidth = 800;
  8. const int screenHeight = 450;
  9. InitWindow(screenWidth, screenHeight, "raylib example.");
  10. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  11. //--------------------------------------------------------------------------------------
  12. // We create a char with some text in it. It must end with '\0'
  13. char savethis[100]="is this allright?\0";
  14. // Save this string as test.txt to the current folder.
  15. SaveFileText("test.txt",savethis);
  16. // Create a char to let our pointer use.
  17. static char myloadstring[128];
  18. // Create a pointer to our char.
  19. static char *loadthis = myloadstring;
  20. // Load the text we saved previously into the loadthis.
  21. loadthis = LoadFileText("test.txt");
  22. // Main game loop
  23. while (!WindowShouldClose()) // Detect window close button or ESC key
  24. {
  25. // Update
  26. //----------------------------------------------------------------------------------
  27. //----------------------------------------------------------------------------------
  28. // Draw
  29. //----------------------------------------------------------------------------------
  30. BeginDrawing();
  31. ClearBackground(RAYWHITE);
  32. // Draw the text from pointer char 'loadthis' to the screen.
  33. DrawText(loadthis,50,50,20,BLACK);
  34. EndDrawing();
  35. //----------------------------------------------------------------------------------
  36. }
  37. // De-Initialization
  38. //--------------------------------------------------------------------------------------
  39. CloseWindow(); // Close window and OpenGL context
  40. //--------------------------------------------------------------------------------------
  41. return 0;
  42. }