So I’m trying to create an application that has user text input, so I went to this link: https://wiki.libsdl.org/Tutorials/TextInput and followed what’s in there but I still seems to be missing something.
This is my code:
#include <stdio.h>
#include <string.h>
#include <SDL2/SDL.h>
extern void InitVideo();
extern void Redraw();
extern char *text;
extern char *composition;
extern Sint32 cursor;
extern Sint32 selection_len;
int main(int argc, char **argv)
{
SDL_bool done = SDL_FALSE;
InitVideo();
/* ... */
SDL_StartTextInput();
while (!done) {
SDL_Event event;
if (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
/* Quit */
done = SDL_TRUE;
break;
case SDL_TEXTINPUT:
/* Add new text onto the end of our text */
strcat(text, event.text.text);
break;
case SDL_TEXTEDITING:
/*
Update the composition text.
Update the cursor position.
Update the selection length (if any).
*/
composition = event.edit.text;
cursor = event.edit.start;
selection_len = event.edit.length;
break;
}
}
Redraw();
}
SDL_Quit();
return 0;
}
I linked the sdl libraries and also included the headers but now I don’t know what am I doing wrong. It always gives me the ‘referenced in function SDL_MAIN’ errors in the line with the ‘extern’ parts.
Was I supposed to define those extern variables my self?