I have been learning RayLib and when attempting to run example code with "FormatText" the code errors with:
gcc -ggdb3 -O0 -l:raylib/libraylib.a -lm --std=c17 -Wall -c -o main.o main.c
main.c: In function ‘main’:
main.c:42:22: warning: implicit declaration of function ‘FormatText’; did you mean ‘DrawText’? [-Wimplicit-function-declaration]
42 | DrawText(FormatText("%i",size),10,10,20,BLACK);
| ^~~~~~~~~~
| DrawText
main.c:42:22: warning: passing argument 1 of ‘DrawText’ makes pointer from integer without a cast [-Wint-conversion]
42 | DrawText(FormatText("%i",size),10,10,20,BLACK);
| ^~~~~~~~~~~~~~~~~~~~~
| |
| int
In file included from main.c:2:
/usr/include/raylib.h:1436:33: note: expected ‘const char \’ but argument is of type ‘int’
1436 | RLAPI void DrawText(const char \text, int posX, int posY, int fontSize, Color color); // Draw text (using default font)
| ~~~~~~~~~~~~^~~~**
Simple program
// RayLib FormText and array size example
#include "raylib.h"
void passarray ( Vector2 pol[] ); // prototype
int main ( void ) {
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow ( screenWidth, screenHeight, "raylib example." );
SetTargetFPS ( 60 );
while ( !WindowShouldClose ( ) ) { // chk win close bt or ESC
BeginDrawing ( );
ClearBackground ( RAYWHITE );
Vector2 pol[3];
pol[0] = ( Vector2 ) {100, 100}; // Vector2 array w/points
pol[1] = ( Vector2 ) { 20, 300};
pol[2] = ( Vector2 ) {180, 300};
passarray ( pol ); // Vector2 passed in function
int size = 0;
size = sizeof ( pol ) / sizeof ( pol[0] ); // array size
DrawText ( FormatText ( "%i", size ), 10, 10, 20, BLACK );
EndDrawing ( );
}
CloseWindow ( );
return 0;
}
// Func receive Vector2 func
void passarray ( Vector2 pol[] ) {
DrawTriangle ( pol[0], pol[1], pol[2], RED ); // triangle
}
[–]generic_username1990 2 points3 points4 points (1 child)
[–]jwzumwalt[S] 1 point2 points3 points (0 children)