Beginners_-_String_To_Integer.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // string char to int.
  3. //
  4. #include "raylib.h"
  5. int main(void)
  6. {
  7. // Initialization
  8. //--------------------------------------------------------------------------------------
  9. const int screenWidth = 800;
  10. const int screenHeight = 450;
  11. InitWindow(screenWidth, screenHeight, "raylib example.");
  12. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  13. //--------------------------------------------------------------------------------------
  14. // Main game loop
  15. while (!WindowShouldClose()) // Detect window close button or ESC key
  16. {
  17. // Update
  18. //----------------------------------------------------------------------------------
  19. // Here we create a char with letters and numbers
  20. char banana[] = "hello 55";
  21. //----------------------------------------------------------------------------------
  22. // Draw
  23. //----------------------------------------------------------------------------------
  24. BeginDrawing();
  25. ClearBackground(RAYWHITE);
  26. //
  27. // by using the -'0' on a character we create its ansi integer value.
  28. // -'0' is decreasing the ansi table with the start position of the numbers in the table.
  29. //
  30. DrawText(FormatText("character [6] of char banana = integer %i",banana[6]-'0'),200,200,20,BLACK);
  31. EndDrawing();
  32. //----------------------------------------------------------------------------------
  33. }
  34. // De-Initialization
  35. //--------------------------------------------------------------------------------------
  36. CloseWindow(); // Close window and OpenGL context
  37. //--------------------------------------------------------------------------------------
  38. return 0;
  39. }